diff --git a/CMakeLists.txt b/CMakeLists.txt index e4018e01..f9802f1d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -19,6 +19,7 @@ set(CMAKE_EXPORT_COMPILE_COMMANDS ON) # Export the compile commands for debuggi set(CMAKE_POLICY_DEFAULT_CMP0063 NEW) # Set CMAKE visibility policy to NEW on project and subprojects set(CMAKE_VISIBILITY_INLINES_HIDDEN ON) # Set C and C++ symbol visibility to hide inlined functions set(CMAKE_MODULE_PATH "${CMAKE_SOURCE_DIR}/cmake") +set(FETCHCONTENT_QUIET FALSE) # GLM takes a long time to clone, this will at least show _something_ while its downloading # Read variables from file FILE(READ "${CMAKE_SOURCE_DIR}/CMakeVariables.txt" variables) @@ -306,7 +307,7 @@ add_subdirectory(dServer) add_subdirectory(dWeb) # Create a list of common libraries shared between all binaries -set(COMMON_LIBRARIES "dCommon" "dDatabase" "dNet" "raknet" "magic_enum") +set(COMMON_LIBRARIES glm::glm "dCommon" "dDatabase" "dNet" "raknet" "magic_enum") # Add platform specific common libraries if(UNIX) diff --git a/cmake/FindGoogleTest.cmake b/cmake/FindGoogleTest.cmake index 69d16247..db0bfb77 100644 --- a/cmake/FindGoogleTest.cmake +++ b/cmake/FindGoogleTest.cmake @@ -6,6 +6,7 @@ FetchContent_Declare( googletest GIT_REPOSITORY https://github.com/google/googletest.git GIT_TAG release-1.12.1 + GIT_PROGRESS TRUE ) # For Windows: Prevent overriding the parent project's compiler/linker settings diff --git a/dAuthServer/AuthServer.cpp b/dAuthServer/AuthServer.cpp index eefbb13e..1905fa73 100644 --- a/dAuthServer/AuthServer.cpp +++ b/dAuthServer/AuthServer.cpp @@ -20,7 +20,7 @@ //Auth includes: #include "AuthPackets.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "MessageType/Server.h" #include "MessageType/Auth.h" @@ -92,7 +92,7 @@ int main(int argc, char** argv) { const auto externalIPString = Game::config->GetValue("external_ip"); if (!externalIPString.empty()) ourIP = externalIPString; - Game::server = new dServer(ourIP, ourPort, 0, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::Auth, Game::config, &Game::lastSignal, masterPassword); + Game::server = new dServer(ourIP, ourPort, 0, maxClients, false, true, Game::logger, masterIP, masterPort, ServiceType::AUTH, Game::config, &Game::lastSignal, masterPassword); //Run it until server gets a kill message from Master: auto t = std::chrono::high_resolution_clock::now(); @@ -167,11 +167,11 @@ void HandlePacket(Packet* packet) { if (packet->length < 4) return; if (packet->data[0] == ID_USER_PACKET_ENUM) { - if (static_cast(packet->data[1]) == eConnectionType::SERVER) { + if (static_cast(packet->data[1]) == ServiceType::COMMON) { if (static_cast(packet->data[3]) == MessageType::Server::VERSION_CONFIRM) { AuthPackets::HandleHandshake(Game::server, packet); } - } else if (static_cast(packet->data[1]) == eConnectionType::AUTH) { + } else if (static_cast(packet->data[1]) == ServiceType::AUTH) { if (static_cast(packet->data[3]) == MessageType::Auth::LOGIN_REQUEST) { AuthPackets::HandleLoginRequest(Game::server, packet); } diff --git a/dChatFilter/CMakeLists.txt b/dChatFilter/CMakeLists.txt index 24b5e428..116b68f3 100644 --- a/dChatFilter/CMakeLists.txt +++ b/dChatFilter/CMakeLists.txt @@ -1,4 +1,4 @@ set(DCHATFILTER_SOURCES "dChatFilter.cpp") add_library(dChatFilter STATIC ${DCHATFILTER_SOURCES}) -target_link_libraries(dChatFilter dDatabase) +target_link_libraries(dChatFilter dDatabase glm::glm) diff --git a/dChatServer/CMakeLists.txt b/dChatServer/CMakeLists.txt index 4d70dd15..d28e02da 100644 --- a/dChatServer/CMakeLists.txt +++ b/dChatServer/CMakeLists.txt @@ -14,6 +14,6 @@ add_compile_definitions(ChatServer PRIVATE PROJECT_VERSION="\"${PROJECT_VERSION} add_library(dChatServer ${DCHATSERVER_SOURCES}) target_include_directories(dChatServer PRIVATE "${PROJECT_SOURCE_DIR}/dServer" "${PROJECT_SOURCE_DIR}/dChatFilter") -target_link_libraries(dChatServer ${COMMON_LIBRARIES} dChatFilter) +target_link_libraries(dChatServer ${COMMON_LIBRARIES} dChatFilter glm::glm) target_link_libraries(ChatServer ${COMMON_LIBRARIES} dChatFilter dChatServer dServer mongoose dWeb) diff --git a/dChatServer/ChatIgnoreList.cpp b/dChatServer/ChatIgnoreList.cpp index 8c0f2f26..025d56dc 100644 --- a/dChatServer/ChatIgnoreList.cpp +++ b/dChatServer/ChatIgnoreList.cpp @@ -13,11 +13,11 @@ // The only thing not auto-handled is instance activities force joining the team on the server. void WriteOutgoingReplyHeader(RakNet::BitStream& bitStream, const LWOOBJID& receivingPlayer, const MessageType::Client type) { - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); bitStream.Write(receivingPlayer); //portion that will get routed: - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, type); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, type); } void ChatIgnoreList::GetIgnoreList(Packet* packet) { diff --git a/dChatServer/ChatPacketHandler.cpp b/dChatServer/ChatPacketHandler.cpp index 5722dfa0..80d1a26f 100644 --- a/dChatServer/ChatPacketHandler.cpp +++ b/dChatServer/ChatPacketHandler.cpp @@ -12,7 +12,7 @@ #include "RakString.h" #include "dConfig.h" #include "eObjectBits.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "MessageType/Chat.h" #include "MessageType/Client.h" #include "MessageType/Game.h" @@ -61,11 +61,11 @@ void ChatPacketHandler::HandleFriendlistRequest(Packet* packet) { //Now, we need to send the friendlist to the server they came from: CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); bitStream.Write(playerID); //portion that will get routed: - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::GET_FRIENDS_LIST_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::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(player.friends.size()); @@ -375,10 +375,10 @@ void ChatPacketHandler::HandleWho(Packet* packet) { bool online = player; CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); bitStream.Write(request.requestor); - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::WHO_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::WHO_RESPONSE); bitStream.Write(online); bitStream.Write(player.zoneID.GetMapID()); bitStream.Write(player.zoneID.GetInstanceID()); @@ -398,10 +398,10 @@ void ChatPacketHandler::HandleShowAll(Packet* packet) { if (!sender) return; CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); bitStream.Write(request.requestor); - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::SHOW_ALL_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::SHOW_ALL_RESPONSE); bitStream.Write(!request.displayZoneData && !request.displayIndividualPlayers); bitStream.Write(Game::playerContainer.GetPlayerCount()); bitStream.Write(Game::playerContainer.GetSimCount()); @@ -533,7 +533,7 @@ void ChatPacketHandler::OnAchievementNotify(RakNet::BitStream& bitstream, const LOG_DEBUG("Sending achievement notify to %s", notify.targetPlayerName.GetAsString().c_str()); RakNet::BitStream worldStream; - BitStreamUtils::WriteHeader(worldStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(worldStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); worldStream.Write(friendData.playerID); notify.WriteHeader(worldStream); notify.Serialize(worldStream); @@ -544,10 +544,10 @@ void ChatPacketHandler::OnAchievementNotify(RakNet::BitStream& bitstream, const void ChatPacketHandler::SendPrivateChatMessage(const PlayerData& sender, const PlayerData& receiver, const PlayerData& routeTo, const LUWString& message, const eChatChannel channel, const eChatMessageResponseCode responseCode) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); bitStream.Write(routeTo.playerID); - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::PRIVATE_CHAT_MESSAGE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::PRIVATE_CHAT_MESSAGE); bitStream.Write(sender.playerID); bitStream.Write(channel); bitStream.Write(0); // not used @@ -579,11 +579,11 @@ void ChatPacketHandler::SendFriendUpdate(const PlayerData& friendData, const Pla [bool] - is FTP*/ CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); bitStream.Write(friendData.playerID); //portion that will get routed: - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::UPDATE_FRIEND_NOTIFY); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::UPDATE_FRIEND_NOTIFY); bitStream.Write(notifyType); std::string playerName = playerData.playerName.c_str(); @@ -616,11 +616,11 @@ void ChatPacketHandler::SendFriendRequest(const PlayerData& receiver, const Play } CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::ADD_FRIEND_REQUEST); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::ADD_FRIEND_REQUEST); bitStream.Write(LUWString(sender.playerName)); bitStream.Write(0); // This is a BFF flag however this is unused in live and does not have an implementation client side. @@ -630,11 +630,11 @@ void ChatPacketHandler::SendFriendRequest(const PlayerData& receiver, const Play void ChatPacketHandler::SendFriendResponse(const PlayerData& receiver, const PlayerData& sender, eAddFriendResponseType responseCode, uint8_t isBestFriendsAlready, uint8_t isBestFriendRequest) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); // Portion that will get routed: - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::ADD_FRIEND_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::ADD_FRIEND_RESPONSE); bitStream.Write(responseCode); // For all requests besides accepted, write a flag that says whether or not we are already best friends with the receiver. bitStream.Write(responseCode != eAddFriendResponseType::ACCEPTED ? isBestFriendsAlready : sender.worldServerSysAddr != UNASSIGNED_SYSTEM_ADDRESS); @@ -653,11 +653,11 @@ void ChatPacketHandler::SendFriendResponse(const PlayerData& receiver, const Pla void ChatPacketHandler::SendRemoveFriend(const PlayerData& receiver, std::string& personToRemove, bool isSuccessful) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::REMOVE_FRIEND_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::REMOVE_FRIEND_RESPONSE); bitStream.Write(isSuccessful); //isOnline bitStream.Write(LUWString(personToRemove)); diff --git a/dChatServer/ChatServer.cpp b/dChatServer/ChatServer.cpp index abc7d779..9cabbf28 100644 --- a/dChatServer/ChatServer.cpp +++ b/dChatServer/ChatServer.cpp @@ -13,7 +13,7 @@ #include "Diagnostics.h" #include "AssetManager.h" #include "BinaryPathFinder.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "PlayerContainer.h" #include "ChatPacketHandler.h" #include "MessageType/Chat.h" @@ -123,7 +123,7 @@ int main(int argc, char** argv) { const auto externalIPString = Game::config->GetValue("external_ip"); if (!externalIPString.empty()) ourIP = externalIPString; - Game::server = new dServer(ourIP, ourPort, 0, maxClients, false, true, Game::logger, masterIP, masterPort, ServerType::Chat, Game::config, &Game::lastSignal, masterPassword); + Game::server = new dServer(ourIP, ourPort, 0, maxClients, false, true, Game::logger, masterIP, masterPort, ServiceType::CHAT, Game::config, &Game::lastSignal, masterPassword); const bool dontGenerateDCF = GeneralUtils::TryParse(Game::config->GetValue("dont_generate_dcf")).value_or(false); Game::chatFilter = new dChatFilter(Game::assetManager->GetResPath().string() + "/chatplus_en_us", dontGenerateDCF); @@ -218,11 +218,11 @@ void HandlePacket(Packet* packet) { CINSTREAM; inStream.SetReadOffset(BYTES_TO_BITS(1)); - eConnectionType connection; - MessageType::Chat chatMessageID; - + ServiceType connection; inStream.Read(connection); - if (connection != eConnectionType::CHAT) return; + if (connection != ServiceType::CHAT) return; + + MessageType::Chat chatMessageID; inStream.Read(chatMessageID); // Our packing byte wasnt there? Probably a false packet diff --git a/dChatServer/PlayerContainer.cpp b/dChatServer/PlayerContainer.cpp index fac6501d..6c75fd1d 100644 --- a/dChatServer/PlayerContainer.cpp +++ b/dChatServer/PlayerContainer.cpp @@ -8,7 +8,7 @@ #include "GeneralUtils.h" #include "BitStreamUtils.h" #include "Database.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "ChatPackets.h" #include "dConfig.h" #include "MessageType/Chat.h" @@ -147,7 +147,7 @@ void PlayerContainer::MuteUpdate(Packet* packet) { void PlayerContainer::BroadcastMuteUpdate(LWOOBJID player, time_t time) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::GM_MUTE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::GM_MUTE); bitStream.Write(player); bitStream.Write(time); diff --git a/dChatServer/TeamContainer.cpp b/dChatServer/TeamContainer.cpp index 024a0464..bbdab0ac 100644 --- a/dChatServer/TeamContainer.cpp +++ b/dChatServer/TeamContainer.cpp @@ -264,11 +264,11 @@ void TeamContainer::HandleTeamStatusRequest(Packet* packet) { void TeamContainer::SendTeamInvite(const PlayerData& receiver, const PlayerData& sender) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::TEAM_INVITE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::TEAM_INVITE); bitStream.Write(LUWString(sender.playerName.c_str())); bitStream.Write(sender.playerID); @@ -279,7 +279,7 @@ void TeamContainer::SendTeamInvite(const PlayerData& receiver, const PlayerData& void TeamContainer::SendTeamInviteConfirm(const PlayerData& receiver, bool bLeaderIsFreeTrial, LWOOBJID i64LeaderID, LWOZONEID i64LeaderZoneID, uint8_t ucLootFlag, uint8_t ucNumOfOtherPlayers, uint8_t ucResponseCode, std::u16string wsLeaderName) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: @@ -306,7 +306,7 @@ void TeamContainer::SendTeamInviteConfirm(const PlayerData& receiver, bool bLead void TeamContainer::SendTeamStatus(const PlayerData& receiver, LWOOBJID i64LeaderID, LWOZONEID i64LeaderZoneID, uint8_t ucLootFlag, uint8_t ucNumOfOtherPlayers, std::u16string wsLeaderName) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: @@ -331,7 +331,7 @@ void TeamContainer::SendTeamStatus(const PlayerData& receiver, LWOOBJID i64Leade void TeamContainer::SendTeamSetLeader(const PlayerData& receiver, LWOOBJID i64PlayerID) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: @@ -348,7 +348,7 @@ void TeamContainer::SendTeamSetLeader(const PlayerData& receiver, LWOOBJID i64Pl void TeamContainer::SendTeamAddPlayer(const PlayerData& receiver, bool bIsFreeTrial, bool bLocal, bool bNoLootOnDeath, LWOOBJID i64PlayerID, std::u16string wsPlayerName, LWOZONEID zoneID) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: @@ -377,7 +377,7 @@ void TeamContainer::SendTeamAddPlayer(const PlayerData& receiver, bool bIsFreeTr void TeamContainer::SendTeamRemovePlayer(const PlayerData& receiver, bool bDisband, bool bIsKicked, bool bIsLeaving, bool bLocal, LWOOBJID i64LeaderID, LWOOBJID i64PlayerID, std::u16string wsPlayerName) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: @@ -403,7 +403,7 @@ void TeamContainer::SendTeamRemovePlayer(const PlayerData& receiver, bool bDisba void TeamContainer::SendTeamSetOffWorldFlag(const PlayerData& receiver, LWOOBJID i64PlayerID, LWOZONEID zoneID) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); bitStream.Write(receiver.playerID); //portion that will get routed: @@ -652,7 +652,7 @@ void TeamContainer::TeamStatusUpdate(TeamData* team) { void TeamContainer::UpdateTeamsOnWorld(TeamData* team, bool deleteTeam) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::TEAM_GET_STATUS); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::TEAM_GET_STATUS); bitStream.Write(team->teamID); bitStream.Write(deleteTeam); diff --git a/dCommon/CMakeLists.txt b/dCommon/CMakeLists.txt index 3a073fc4..2945d3db 100644 --- a/dCommon/CMakeLists.txt +++ b/dCommon/CMakeLists.txt @@ -54,6 +54,7 @@ elseif (WIN32) zlib URL https://github.com/madler/zlib/archive/refs/tags/v1.2.11.zip URL_HASH MD5=9d6a627693163bbbf3f26403a3a0b0b1 + GIT_PROGRESS TRUE ) # Disable warning about no project version. @@ -74,5 +75,6 @@ else () endif () target_link_libraries(dCommon + PUBLIC glm::glm PRIVATE ZLIB::ZLIB bcrypt tinyxml2 INTERFACE dDatabase) diff --git a/dCommon/GeneralUtils.h b/dCommon/GeneralUtils.h index 57806a16..b5915739 100644 --- a/dCommon/GeneralUtils.h +++ b/dCommon/GeneralUtils.h @@ -20,6 +20,8 @@ #include "Game.h" #include "Logger.h" +#include + enum eInventoryType : uint32_t; enum class eObjectBits : size_t; enum class eReplicaComponentType : uint32_t; @@ -244,7 +246,7 @@ namespace GeneralUtils { * @returns An std::optional containing the desired NiPoint3 if it can be constructed from the string parameters */ template - [[nodiscard]] std::optional TryParse(const std::string_view strX, const std::string_view strY, const std::string_view strZ) { + [[nodiscard]] std::optional TryParse(const std::string_view strX, const std::string_view strY, const std::string_view strZ) { const auto x = TryParse(strX); if (!x) return std::nullopt; @@ -252,7 +254,7 @@ namespace GeneralUtils { if (!y) return std::nullopt; const auto z = TryParse(strZ); - return z ? std::make_optional(x.value(), y.value(), z.value()) : std::nullopt; + return z ? std::make_optional(x.value(), y.value(), z.value()) : std::nullopt; } /** @@ -261,8 +263,8 @@ namespace GeneralUtils { * @returns An std::optional containing the desired NiPoint3 if it can be constructed from the string parameters */ template - [[nodiscard]] std::optional TryParse(const std::span str) { - return (str.size() == 3) ? TryParse(str[0], str[1], str[2]) : std::nullopt; + [[nodiscard]] std::optional TryParse(const std::span str) { + return (str.size() == 3) ? TryParse(str[0], str[1], str[2]) : std::nullopt; } template diff --git a/dCommon/NiPoint3.h b/dCommon/NiPoint3.h index 00d09083..b968a4de 100644 --- a/dCommon/NiPoint3.h +++ b/dCommon/NiPoint3.h @@ -6,10 +6,14 @@ \brief Defines a point in space in XYZ coordinates */ + class NiPoint3; -class NiQuaternion; typedef NiPoint3 Vector3; //!< The Vector3 class is technically the NiPoint3 class, but typedef'd for clarity in some cases +#include + +#include "NiQuaternion.h" + //! A custom class the defines a point in space class NiPoint3 { public: @@ -21,6 +25,12 @@ public: //! Initializer constexpr NiPoint3() = default; + constexpr NiPoint3(const glm::vec3& vec) noexcept + : x{ vec.x } + , y{ vec.y } + , z{ vec.z } { + } + //! Initializer /*! \param x The x coordinate diff --git a/dCommon/NiPoint3.inl b/dCommon/NiPoint3.inl index 48aa3ae1..db842ec6 100644 --- a/dCommon/NiPoint3.inl +++ b/dCommon/NiPoint3.inl @@ -4,6 +4,7 @@ #endif #include "NiQuaternion.h" +#include // MARK: Getters / Setters diff --git a/dCommon/NiQuaternion.cpp b/dCommon/NiQuaternion.cpp index 1677e180..77afa61b 100644 --- a/dCommon/NiQuaternion.cpp +++ b/dCommon/NiQuaternion.cpp @@ -3,32 +3,12 @@ // C++ #include +#include + // MARK: Member Functions -Vector3 NiQuaternion::GetEulerAngles() const { - Vector3 angles; - - // roll (x-axis rotation) - const float sinr_cosp = 2 * (w * x + y * z); - const float cosr_cosp = 1 - 2 * (x * x + y * y); - angles.x = std::atan2(sinr_cosp, cosr_cosp); - - // pitch (y-axis rotation) - const float t2 = 2 * (w * y - z * x); - angles.y = std::asin(std::clamp(t2, -1.0f, 1.0f)); // clamp to avoid NaN - - // if (std::abs(p) >= 1) { - // angles.y = std::copysign(3.14 / 2, p); // use 90 degrees if out of range - // } else { - // angles.y = std::asin(p); - // } - - // yaw (z-axis rotation) - const float siny_cosp = 2 * (w * z + x * y); - const float cosy_cosp = 1 - 2 * (y * y + z * z); - angles.z = std::atan2(siny_cosp, cosy_cosp); - - return angles; +Vector3 QuatUtils::Euler(const NiQuaternion& quat) { + return glm::eulerAngles(quat); } NiQuaternion NiQuaternion::operator*(const float scalar) const noexcept { @@ -93,7 +73,7 @@ NiQuaternion NiQuaternion::Diff(const NiQuaternion& q) const noexcept { // MARK: Helper Functions //! Look from a specific point in space to another point in space (Y-locked) -NiQuaternion NiQuaternion::LookAt(const NiPoint3& sourcePoint, const NiPoint3& destPoint) { +NiQuaternion QuatUtils::LookAt(const NiPoint3& sourcePoint, const NiPoint3& destPoint) { //To make sure we don't orient around the X/Z axis: NiPoint3 source = sourcePoint; NiPoint3 dest = destPoint; @@ -111,11 +91,11 @@ NiQuaternion NiQuaternion::LookAt(const NiPoint3& sourcePoint, const NiPoint3& d NiPoint3 vecB = vecA.CrossProduct(posZ); if (vecB.DotProduct(forwardVector) < 0) rotAngle = -rotAngle; - return NiQuaternion::CreateFromAxisAngle(vecA, rotAngle); + return glm::angleAxis(rotAngle, glm::vec3{vecA.x, vecA.y, vecA.z}); } //! Look from a specific point in space to another point in space -NiQuaternion NiQuaternion::LookAtUnlocked(const NiPoint3& sourcePoint, const NiPoint3& destPoint) { +NiQuaternion QuatUtils::LookAtUnlocked(const NiPoint3& sourcePoint, const NiPoint3& destPoint) { NiPoint3 forwardVector = NiPoint3(destPoint - sourcePoint).Unitize(); NiPoint3 posZ = NiPoint3Constant::UNIT_Z; @@ -127,37 +107,26 @@ NiQuaternion NiQuaternion::LookAtUnlocked(const NiPoint3& sourcePoint, const NiP NiPoint3 vecB = vecA.CrossProduct(posZ); if (vecB.DotProduct(forwardVector) < 0) rotAngle = -rotAngle; - return NiQuaternion::CreateFromAxisAngle(vecA, rotAngle); + return glm::angleAxis(rotAngle, glm::vec3{vecA.x, vecA.y, vecA.z}); } //! Creates a Quaternion from a specific axis and angle relative to that axis -NiQuaternion NiQuaternion::CreateFromAxisAngle(const Vector3& axis, float angle) { - float halfAngle = angle * 0.5f; - float s = static_cast(sin(halfAngle)); - - NiQuaternion q; - q.x = axis.GetX() * s; - q.y = axis.GetY() * s; - q.z = axis.GetZ() * s; - q.w = static_cast(cos(halfAngle)); - - return q; +NiQuaternion QuatUtils::AxisAngle(const Vector3& axis, float angle) { + return glm::angleAxis(angle, glm::vec3(axis.x, axis.y, axis.z)); } -NiQuaternion NiQuaternion::FromEulerAngles(const NiPoint3& eulerAngles) { - // Abbreviations for the various angular functions - float cy = cos(eulerAngles.z * 0.5); - float sy = sin(eulerAngles.z * 0.5); - float cp = cos(eulerAngles.y * 0.5); - float sp = sin(eulerAngles.y * 0.5); - float cr = cos(eulerAngles.x * 0.5); - float sr = sin(eulerAngles.x * 0.5); - - NiQuaternion q; - q.w = cr * cp * cy + sr * sp * sy; - q.x = sr * cp * cy - cr * sp * sy; - q.y = cr * sp * cy + sr * cp * sy; - q.z = cr * cp * sy - sr * sp * cy; - - return q; +NiQuaternion QuatUtils::FromEuler(const NiPoint3& eulerAngles) { + return glm::quat(glm::vec3(eulerAngles.x, eulerAngles.y, eulerAngles.z)); +} + +Vector3 QuatUtils::Forward(const NiQuaternion& quat) { + return quat * glm::vec3(0, 0, 1); +} + +Vector3 QuatUtils::Up(const NiQuaternion& quat) { + return quat * glm::vec3(0, 1, 0); +} + +Vector3 QuatUtils::Right(const NiQuaternion& quat) { + return quat * glm::vec3(1, 0, 0); } diff --git a/dCommon/NiQuaternion.h b/dCommon/NiQuaternion.h index f4b380c3..a4546e2c 100644 --- a/dCommon/NiQuaternion.h +++ b/dCommon/NiQuaternion.h @@ -1,170 +1,27 @@ -#ifndef __NIQUATERNION_H__ -#define __NIQUATERNION_H__ +#ifndef NIQUATERNION_H +#define NIQUATERNION_H // Custom Classes #include "NiPoint3.h" -/*! - \file NiQuaternion.hpp - \brief Defines a quaternion in space in WXYZ coordinates - */ +#define GLM_FORCE_QUAT_DATA_WXYZ -class NiQuaternion; -typedef NiQuaternion Quaternion; //!< A typedef for a shorthand version of NiQuaternion +#include -//! A class that defines a rotation in space -class NiQuaternion { -public: - float w{ 1 }; //!< The w coordinate - float x{ 0 }; //!< The x coordinate - float y{ 0 }; //!< The y coordinate - float z{ 0 }; //!< The z coordinate +using Quaternion = glm::quat; +using NiQuaternion = Quaternion; - - //! The initializer - constexpr NiQuaternion() = default; - - //! The initializer - /*! - \param w The w coordinate - \param x The x coordinate - \param y The y coordinate - \param z The z coordinate - */ - constexpr NiQuaternion(const float w, const float x, const float y, const float z) noexcept - : w{ w } - , x{ x } - , y{ y } - , z{ z } { - } - - // MARK: Setters / Getters - - //! Gets the W coordinate - /*! - \return The w coordinate - */ - [[nodiscard]] constexpr float GetW() const noexcept; - - //! Sets the W coordinate - /*! - \param w The w coordinate - */ - constexpr void SetW(const float w) noexcept; - - //! Gets the X coordinate - /*! - \return The x coordinate - */ - [[nodiscard]] constexpr float GetX() const noexcept; - - //! Sets the X coordinate - /*! - \param x The x coordinate - */ - constexpr void SetX(const float x) noexcept; - - //! Gets the Y coordinate - /*! - \return The y coordinate - */ - [[nodiscard]] constexpr float GetY() const noexcept; - - //! Sets the Y coordinate - /*! - \param y The y coordinate - */ - constexpr void SetY(const float y) noexcept; - - //! Gets the Z coordinate - /*! - \return The z coordinate - */ - [[nodiscard]] constexpr float GetZ() const noexcept; - - //! Sets the Z coordinate - /*! - \param z The z coordinate - */ - constexpr void SetZ(const float z) noexcept; - - // MARK: Member Functions - - //! Returns the forward vector from the quaternion - /*! - \return The forward vector of the quaternion - */ - [[nodiscard]] constexpr Vector3 GetForwardVector() const noexcept; - - //! Returns the up vector from the quaternion - /*! - \return The up vector fo the quaternion - */ - [[nodiscard]] constexpr Vector3 GetUpVector() const noexcept; - - //! Returns the right vector from the quaternion - /*! - \return The right vector of the quaternion - */ - [[nodiscard]] constexpr Vector3 GetRightVector() const noexcept; - - [[nodiscard]] Vector3 GetEulerAngles() const; - - NiQuaternion operator*(const float scalar) const noexcept; - - NiQuaternion operator*(const NiQuaternion& q) const noexcept; - NiQuaternion operator/(const float& q) const noexcept; - NiQuaternion& operator*=(const NiQuaternion& q) noexcept; - float Dot(const NiQuaternion& q) const noexcept; - void Inverse() noexcept; - void Conjugate() noexcept; - NiQuaternion Diff(const NiQuaternion& q) const noexcept; - - void Normalize(); - - // MARK: Operators - - //! Operator to check for equality - constexpr bool operator==(const NiQuaternion& rot) const noexcept; - - //! Operator to check for inequality - constexpr bool operator!=(const NiQuaternion& rot) const noexcept; - - // MARK: Helper Functions - - //! Look from a specific point in space to another point in space (Y-locked) - /*! - \param sourcePoint The source location - \param destPoint The destination location - \return The Quaternion with the rotation towards the destination - */ - [[nodiscard]] static NiQuaternion LookAt(const NiPoint3& sourcePoint, const NiPoint3& destPoint); - - //! Look from a specific point in space to another point in space - /*! - \param sourcePoint The source location - \param destPoint The destination location - \return The Quaternion with the rotation towards the destination - */ - [[nodiscard]] static NiQuaternion LookAtUnlocked(const NiPoint3& sourcePoint, const NiPoint3& destPoint); - - //! Creates a Quaternion from a specific axis and angle relative to that axis - /*! - \param axis The axis that is used - \param angle The angle relative to this axis - \return A quaternion created from the axis and angle - */ - [[nodiscard]] static NiQuaternion CreateFromAxisAngle(const Vector3& axis, float angle); - - [[nodiscard]] static NiQuaternion FromEulerAngles(const NiPoint3& eulerAngles); +namespace QuatUtils { + constexpr NiQuaternion IDENTITY = glm::identity(); + Vector3 Forward(const NiQuaternion& quat); + Vector3 Up(const NiQuaternion& quat); + Vector3 Right(const NiQuaternion& quat); + NiQuaternion LookAt(const NiPoint3& from, const NiPoint3& to); + NiQuaternion LookAtUnlocked(const NiPoint3& from, const NiPoint3& to); + Vector3 Euler(const NiQuaternion& quat); + NiQuaternion AxisAngle(const Vector3& axis, float angle); + NiQuaternion FromEuler(const NiPoint3& eulerAngles); + constexpr float PI_OVER_180 = glm::pi() / 180.0f; }; -// Static Variables -namespace NiQuaternionConstant { - constexpr NiQuaternion IDENTITY(1, 0, 0, 0); -} - -// Include constexpr and inline function definitions in a seperate file for readability -#include "NiQuaternion.inl" - -#endif // !__NIQUATERNION_H__ +#endif // !NIQUATERNION_H diff --git a/dCommon/NiQuaternion.inl b/dCommon/NiQuaternion.inl deleted file mode 100644 index 9ed84ffc..00000000 --- a/dCommon/NiQuaternion.inl +++ /dev/null @@ -1,75 +0,0 @@ -#pragma once -#ifndef __NIQUATERNION_H__ -#error "This should only be included inline in NiQuaternion.h: Do not include directly!" -#endif - -// MARK: Setters / Getters - -//! Gets the W coordinate -constexpr float NiQuaternion::GetW() const noexcept { - return this->w; -} - -//! Sets the W coordinate -constexpr void NiQuaternion::SetW(const float w) noexcept { - this->w = w; -} - -//! Gets the X coordinate -constexpr float NiQuaternion::GetX() const noexcept { - return this->x; -} - -//! Sets the X coordinate -constexpr void NiQuaternion::SetX(const float x) noexcept { - this->x = x; -} - -//! Gets the Y coordinate -constexpr float NiQuaternion::GetY() const noexcept { - return this->y; -} - -//! Sets the Y coordinate -constexpr void NiQuaternion::SetY(const float y) noexcept { - this->y = y; -} - -//! Gets the Z coordinate -constexpr float NiQuaternion::GetZ() const noexcept { - return this->z; -} - -//! Sets the Z coordinate -constexpr void NiQuaternion::SetZ(const float z) noexcept { - this->z = z; -} - -// MARK: Member Functions - -//! Returns the forward vector from the quaternion -constexpr Vector3 NiQuaternion::GetForwardVector() const noexcept { - return Vector3(2 * (x * z + w * y), 2 * (y * z - w * x), 1 - 2 * (x * x + y * y)); -} - -//! Returns the up vector from the quaternion -constexpr Vector3 NiQuaternion::GetUpVector() const noexcept { - return Vector3(2 * (x * y - w * z), 1 - 2 * (x * x + z * z), 2 * (y * z + w * x)); -} - -//! Returns the right vector from the quaternion -constexpr Vector3 NiQuaternion::GetRightVector() const noexcept { - return Vector3(1 - 2 * (y * y + z * z), 2 * (x * y + w * z), 2 * (x * z - w * y)); -} - -// MARK: Operators - -//! Operator to check for equality -constexpr bool NiQuaternion::operator==(const NiQuaternion& rot) const noexcept { - return rot.x == this->x && rot.y == this->y && rot.z == this->z && rot.w == this->w; -} - -//! Operator to check for inequality -constexpr bool NiQuaternion::operator!=(const NiQuaternion& rot) const noexcept { - return !(*this == rot); -} diff --git a/dCommon/PositionUpdate.h b/dCommon/PositionUpdate.h index f28c682d..1c618ba0 100644 --- a/dCommon/PositionUpdate.h +++ b/dCommon/PositionUpdate.h @@ -24,7 +24,7 @@ struct LocalSpaceInfo { struct PositionUpdate { NiPoint3 position = NiPoint3Constant::ZERO; - NiQuaternion rotation = NiQuaternionConstant::IDENTITY; + NiQuaternion rotation = QuatUtils::IDENTITY; bool onGround = false; bool onRail = false; NiPoint3 velocity = NiPoint3Constant::ZERO; diff --git a/dCommon/dEnums/ServiceType.h b/dCommon/dEnums/ServiceType.h new file mode 100644 index 00000000..92c9c7bd --- /dev/null +++ b/dCommon/dEnums/ServiceType.h @@ -0,0 +1,14 @@ +#ifndef __SERVICETYPE__H__ +#define __SERVICETYPE__H__ + +enum class ServiceType : uint16_t { + COMMON = 0, + AUTH, + CHAT, + WORLD = 4, + CLIENT, + MASTER, + UNKNOWN +}; + +#endif //!__SERVICETYPE__H__ diff --git a/dCommon/dEnums/dCommonVars.h b/dCommon/dEnums/dCommonVars.h index ad127876..c74b9c21 100644 --- a/dCommon/dEnums/dCommonVars.h +++ b/dCommon/dEnums/dCommonVars.h @@ -10,7 +10,7 @@ #include "BitStream.h" #include "BitStreamUtils.h" #include "MessageType/Client.h" -#include "eConnectionType.h" +#include "ServiceType.h" #pragma warning (disable:4251) //Disables SQL warnings @@ -34,7 +34,7 @@ constexpr uint32_t lowFrameDelta = FRAMES_TO_MS(lowFramerate); #define CBITSTREAM RakNet::BitStream bitStream; #define CINSTREAM RakNet::BitStream inStream(packet->data, packet->length, false); #define CINSTREAM_SKIP_HEADER CINSTREAM if (inStream.GetNumberOfUnreadBits() >= BYTES_TO_BITS(HEADER_SIZE)) inStream.IgnoreBytes(HEADER_SIZE); else inStream.IgnoreBits(inStream.GetNumberOfUnreadBits()); -#define CMSGHEADER BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::GAME_MSG); +#define CMSGHEADER BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::GAME_MSG); #define SEND_PACKET Game::server->Send(bitStream, sysAddr, false); #define SEND_PACKET_BROADCAST Game::server->Send(bitStream, UNASSIGNED_SYSTEM_ADDRESS, true); diff --git a/dCommon/dEnums/eConnectionType.h b/dCommon/dEnums/eConnectionType.h deleted file mode 100644 index ed75e100..00000000 --- a/dCommon/dEnums/eConnectionType.h +++ /dev/null @@ -1,14 +0,0 @@ -#ifndef __ECONNECTIONTYPE__H__ -#define __ECONNECTIONTYPE__H__ - -enum class eConnectionType : uint16_t { - SERVER = 0, - AUTH, - CHAT, - WORLD = 4, - CLIENT, - MASTER, - UNKNOWN -}; - -#endif //!__ECONNECTIONTYPE__H__ diff --git a/dDatabase/CDClientDatabase/CMakeLists.txt b/dDatabase/CDClientDatabase/CMakeLists.txt index 13d59ffb..9aca3bda 100644 --- a/dDatabase/CDClientDatabase/CMakeLists.txt +++ b/dDatabase/CDClientDatabase/CMakeLists.txt @@ -15,7 +15,7 @@ target_include_directories(dDatabaseCDClient PUBLIC "." "${PROJECT_SOURCE_DIR}/dCommon" "${PROJECT_SOURCE_DIR}/dCommon/dEnums" ) -target_link_libraries(dDatabaseCDClient PRIVATE sqlite3) +target_link_libraries(dDatabaseCDClient PRIVATE sqlite3 glm::glm) if (${CDCLIENT_CACHE_ALL}) add_compile_definitions(dDatabaseCDClient PRIVATE CDCLIENT_CACHE_ALL=${CDCLIENT_CACHE_ALL}) diff --git a/dDatabase/CMakeLists.txt b/dDatabase/CMakeLists.txt index 56ed4df7..63bd5fb6 100644 --- a/dDatabase/CMakeLists.txt +++ b/dDatabase/CMakeLists.txt @@ -10,4 +10,5 @@ add_dependencies(dDatabase conncpp_dylib) target_include_directories(dDatabase PUBLIC ".") target_link_libraries(dDatabase - PUBLIC dDatabaseCDClient dDatabaseGame) + PUBLIC dDatabaseCDClient dDatabaseGame + PRIVATE glm::glm) diff --git a/dDatabase/GameDatabase/CMakeLists.txt b/dDatabase/GameDatabase/CMakeLists.txt index fc5500ec..881969ef 100644 --- a/dDatabase/GameDatabase/CMakeLists.txt +++ b/dDatabase/GameDatabase/CMakeLists.txt @@ -29,7 +29,7 @@ target_include_directories(dDatabaseGame PUBLIC "." target_link_libraries(dDatabaseGame INTERFACE dCommon - PRIVATE sqlite3 MariaDB::ConnCpp) + PRIVATE sqlite3 MariaDB::ConnCpp glm::glm) # Glob together all headers that need to be precompiled file( diff --git a/dDatabase/GameDatabase/ITables/IPropertyContents.h b/dDatabase/GameDatabase/ITables/IPropertyContents.h index 82cbcc77..1c51d00c 100644 --- a/dDatabase/GameDatabase/ITables/IPropertyContents.h +++ b/dDatabase/GameDatabase/ITables/IPropertyContents.h @@ -13,7 +13,7 @@ public: } NiPoint3 position; - NiQuaternion rotation; + NiQuaternion rotation = QuatUtils::IDENTITY; LWOOBJID id{}; LOT lot{}; uint32_t ugcId{}; diff --git a/dGame/Character.cpp b/dGame/Character.cpp index 13ac5e37..0af51a1c 100644 --- a/dGame/Character.cpp +++ b/dGame/Character.cpp @@ -496,7 +496,7 @@ void Character::OnZoneLoad() { // Remove all GM items for (const auto lot : Inventory::GetAllGMItems()) { - inventoryComponent->RemoveItem(lot, inventoryComponent->GetLotCount(lot)); + inventoryComponent->RemoveItem(lot, inventoryComponent->GetLotCount(lot), eInventoryType::ALL); } } diff --git a/dGame/Character.h b/dGame/Character.h index 99ed9855..bcddfd3e 100644 --- a/dGame/Character.h +++ b/dGame/Character.h @@ -654,7 +654,7 @@ private: /** * The spawn rotation of this character when loading in */ - NiQuaternion m_OriginalRotation; + NiQuaternion m_OriginalRotation = QuatUtils::IDENTITY; /** * The respawn points of this character, per world diff --git a/dGame/Entity.cpp b/dGame/Entity.cpp index 73325f8f..543f324a 100644 --- a/dGame/Entity.cpp +++ b/dGame/Entity.cpp @@ -175,8 +175,11 @@ Entity::~Entity() { CancelAllTimers(); CancelCallbackTimers(); - for (const auto& component : m_Components | std::views::values) { - if (component) delete component; + for (auto& component : m_Components | std::views::values) { + if (component) { + delete component; + component = nullptr; + } } for (auto* const child : m_ChildEntities) { @@ -301,7 +304,7 @@ void Entity::Initialize() { //If we came from another zone, put us in the starting loc if (m_Character->GetZoneID() != Game::server->GetZoneID() || mapID == 1603) { // Exception for Moon Base as you tend to spawn on the roof. NiPoint3 pos; - NiQuaternion rot; + NiQuaternion rot = QuatUtils::IDENTITY; const auto& targetSceneName = m_Character->GetTargetScene(); auto* targetScene = Game::entityManager->GetSpawnPointEntity(targetSceneName); @@ -902,7 +905,7 @@ void Entity::SetGMLevel(eGameMasterLevel value) { // Update the chat server of our GM Level { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::GMLEVEL_UPDATE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::GMLEVEL_UPDATE); bitStream.Write(m_ObjectID); bitStream.Write(m_GMLevel); @@ -1879,7 +1882,7 @@ const NiQuaternion& Entity::GetRotation() const { return rigidBodyPhantomPhysicsComponent->GetRotation(); } - return NiQuaternionConstant::IDENTITY; + return QuatUtils::IDENTITY; } void Entity::SetPosition(const NiPoint3& position) { @@ -2175,7 +2178,7 @@ const NiPoint3& Entity::GetRespawnPosition() const { const NiQuaternion& Entity::GetRespawnRotation() const { auto* characterComponent = GetComponent(); - return characterComponent ? characterComponent->GetRespawnRotation() : NiQuaternionConstant::IDENTITY; + return characterComponent ? characterComponent->GetRespawnRotation() : QuatUtils::IDENTITY; } void Entity::SetRespawnPos(const NiPoint3& position) const { diff --git a/dGame/Entity.h b/dGame/Entity.h index 469ac5ea..f9498854 100644 --- a/dGame/Entity.h +++ b/dGame/Entity.h @@ -357,7 +357,7 @@ private: std::vector m_NetworkSettings; NiPoint3 m_DefaultPosition; - NiQuaternion m_DefaultRotation; + NiQuaternion m_DefaultRotation = QuatUtils::IDENTITY; float m_Scale; Spawner* m_Spawner; diff --git a/dGame/UserManager.cpp b/dGame/UserManager.cpp index 886e3415..6b742b27 100644 --- a/dGame/UserManager.cpp +++ b/dGame/UserManager.cpp @@ -25,7 +25,7 @@ #include "eGameMasterLevel.h" #include "eCharacterCreationResponse.h" #include "eRenameResponse.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "MessageType/Chat.h" #include "BitStreamUtils.h" #include "CheatDetection.h" @@ -217,7 +217,7 @@ void UserManager::RequestCharacterList(const SystemAddress& sysAddr) { } RakNet::BitStream bitStream; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::CHARACTER_LIST_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::CHARACTER_LIST_RESPONSE); std::vector characters = u->GetCharacters(); bitStream.Write(characters.size()); @@ -427,7 +427,7 @@ void UserManager::DeleteCharacter(const SystemAddress& sysAddr, Packet* packet) Database::Get()->DeleteCharacter(charID); CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::UNEXPECTED_DISCONNECT); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::UNEXPECTED_DISCONNECT); bitStream.Write(objectID); Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false); diff --git a/dGame/dBehaviors/BehaviorContext.cpp b/dGame/dBehaviors/BehaviorContext.cpp index 452df3ad..c8c126b6 100644 --- a/dGame/dBehaviors/BehaviorContext.cpp +++ b/dGame/dBehaviors/BehaviorContext.cpp @@ -16,7 +16,7 @@ #include "QuickBuildComponent.h" #include "eReplicaComponentType.h" #include "TeamManager.h" -#include "eConnectionType.h" +#include "ServiceType.h" BehaviorSyncEntry::BehaviorSyncEntry() { } @@ -212,7 +212,7 @@ void BehaviorContext::UpdatePlayerSyncs(float deltaTime) { echo.sBitStream.assign(reinterpret_cast(bitStream.GetData()), bitStream.GetNumberOfBytesUsed()); RakNet::BitStream message; - BitStreamUtils::WriteHeader(message, eConnectionType::CLIENT, MessageType::Client::GAME_MSG); + BitStreamUtils::WriteHeader(message, ServiceType::CLIENT, MessageType::Client::GAME_MSG); message.Write(this->originator); echo.Serialize(message); @@ -285,7 +285,7 @@ bool BehaviorContext::CalculateUpdate(const float deltaTime) { // Write message RakNet::BitStream message; - BitStreamUtils::WriteHeader(message, eConnectionType::CLIENT, MessageType::Client::GAME_MSG); + BitStreamUtils::WriteHeader(message, ServiceType::CLIENT, MessageType::Client::GAME_MSG); message.Write(this->originator); echo.Serialize(message); diff --git a/dGame/dBehaviors/ChangeOrientationBehavior.cpp b/dGame/dBehaviors/ChangeOrientationBehavior.cpp index f8a34fb8..e6717261 100644 --- a/dGame/dBehaviors/ChangeOrientationBehavior.cpp +++ b/dGame/dBehaviors/ChangeOrientationBehavior.cpp @@ -3,6 +3,8 @@ #include "BehaviorContext.h" #include "EntityManager.h" +#include + void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitStream, BehaviorBranchContext branch) { Entity* sourceEntity; if (this->m_orientCaster) sourceEntity = Game::entityManager->GetEntity(context->originator); @@ -16,12 +18,12 @@ void ChangeOrientationBehavior::Calculate(BehaviorContext* context, RakNet::BitS if (!destinationEntity) return; sourceEntity->SetRotation( - NiQuaternion::LookAt(sourceEntity->GetPosition(), destinationEntity->GetPosition()) + QuatUtils::LookAt(sourceEntity->GetPosition(), destinationEntity->GetPosition()) ); } else if (this->m_toAngle){ auto baseAngle = NiPoint3(0, 0, this->m_angle); - if (this->m_relative) baseAngle += sourceEntity->GetRotation().GetForwardVector(); - sourceEntity->SetRotation(NiQuaternion::FromEulerAngles(baseAngle)); + if (this->m_relative) baseAngle += QuatUtils::Forward(sourceEntity->GetRotation()); + sourceEntity->SetRotation(glm::quat(glm::vec3(baseAngle.x, baseAngle.y, baseAngle.z))); } else return; Game::entityManager->SerializeEntity(sourceEntity); return; diff --git a/dGame/dBehaviors/ConsumeItemBehavior.cpp b/dGame/dBehaviors/ConsumeItemBehavior.cpp index 440a641b..66745ee7 100644 --- a/dGame/dBehaviors/ConsumeItemBehavior.cpp +++ b/dGame/dBehaviors/ConsumeItemBehavior.cpp @@ -12,7 +12,7 @@ void ConsumeItemBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bi auto inventoryComponent = caster->GetComponent(); if (!inventoryComponent) return; - if (inventoryComponent->RemoveItem(this->m_ConsumeLOT, this->m_NumToConsume, eInventoryType::INVALID, false, true)){ + if (inventoryComponent->RemoveItem(this->m_ConsumeLOT, this->m_NumToConsume, eInventoryType::ALL, false, true)){ action_to_cast = m_ActionConsumed; } } diff --git a/dGame/dBehaviors/ForceMovementBehavior.cpp b/dGame/dBehaviors/ForceMovementBehavior.cpp index 04dad715..289c580b 100644 --- a/dGame/dBehaviors/ForceMovementBehavior.cpp +++ b/dGame/dBehaviors/ForceMovementBehavior.cpp @@ -48,7 +48,7 @@ void ForceMovementBehavior::Calculate(BehaviorContext* context, RakNet::BitStrea if (controllablePhysicsComponent != nullptr) { if (m_Forward == 1) { - controllablePhysicsComponent->SetVelocity(controllablePhysicsComponent->GetRotation().GetForwardVector() * 25); + controllablePhysicsComponent->SetVelocity(QuatUtils::Forward(controllablePhysicsComponent->GetRotation()) * 25); } Game::entityManager->SerializeEntity(casterEntity); diff --git a/dGame/dBehaviors/ProjectileAttackBehavior.cpp b/dGame/dBehaviors/ProjectileAttackBehavior.cpp index 3e5118f7..5e9768e6 100644 --- a/dGame/dBehaviors/ProjectileAttackBehavior.cpp +++ b/dGame/dBehaviors/ProjectileAttackBehavior.cpp @@ -92,7 +92,7 @@ void ProjectileAttackBehavior::Calculate(BehaviorContext* context, RakNet::BitSt const auto time = distance / this->m_projectileSpeed; - const auto rotation = NiQuaternion::LookAtUnlocked(position, other->GetPosition()); + const auto rotation = QuatUtils::LookAtUnlocked(position, other->GetPosition()); const auto targetPosition = other->GetPosition(); @@ -112,13 +112,13 @@ void ProjectileAttackBehavior::Calculate(BehaviorContext* context, RakNet::BitSt bitStream.Write(id); - auto eulerAngles = rotation.GetEulerAngles(); + auto eulerAngles = QuatUtils::Euler(rotation); - eulerAngles.y += angle * (3.14 / 180); + eulerAngles.y += angle * (glm::pi() / 180.0f); - const auto angledRotation = NiQuaternion::FromEulerAngles(eulerAngles); + const auto angledRotation = QuatUtils::FromEuler(eulerAngles); - const auto direction = angledRotation.GetForwardVector(); + const auto direction = QuatUtils::Forward(angledRotation); const auto destination = position + direction * distance; diff --git a/dGame/dBehaviors/SpawnBehavior.cpp b/dGame/dBehaviors/SpawnBehavior.cpp index e033d368..8d3a51da 100644 --- a/dGame/dBehaviors/SpawnBehavior.cpp +++ b/dGame/dBehaviors/SpawnBehavior.cpp @@ -36,7 +36,7 @@ void SpawnBehavior::Handle(BehaviorContext* context, RakNet::BitStream& bitStrea info.spawner = nullptr; info.spawnerID = context->originator; info.spawnerNodeID = 0; - info.pos = info.pos + (info.rot.GetForwardVector() * m_Distance); + info.pos = info.pos + (QuatUtils::Forward(info.rot) * m_Distance); auto* entity = Game::entityManager->CreateEntity( info, diff --git a/dGame/dBehaviors/TacArcBehavior.cpp b/dGame/dBehaviors/TacArcBehavior.cpp index cb3430c8..3e477896 100644 --- a/dGame/dBehaviors/TacArcBehavior.cpp +++ b/dGame/dBehaviors/TacArcBehavior.cpp @@ -125,7 +125,7 @@ void TacArcBehavior::Calculate(BehaviorContext* context, RakNet::BitStream& bitS if (targetPos.y > reference.y && heightDifference > this->m_upperBound || targetPos.y < reference.y && heightDifference > this->m_lowerBound) continue; - const auto forward = self->GetRotation().GetForwardVector(); + const auto forward = QuatUtils::Forward(self->GetRotation()); // forward is a normalized vector of where the caster is facing. // targetPos is the position of the target. diff --git a/dGame/dComponents/AchievementVendorComponent.cpp b/dGame/dComponents/AchievementVendorComponent.cpp index 006a2b6f..5ac03102 100644 --- a/dGame/dComponents/AchievementVendorComponent.cpp +++ b/dGame/dComponents/AchievementVendorComponent.cpp @@ -64,12 +64,11 @@ void AchievementVendorComponent::Buy(Entity* buyer, LOT lot, uint32_t count) { } const uint32_t altCurrencyCost = itemComp.commendationCost * count; - if (inventoryComponent->GetLotCount(costLOT) < altCurrencyCost) { + if (inventoryComponent->GetLotCount(costLOT) < altCurrencyCost || !inventoryComponent->RemoveItem(costLOT, altCurrencyCost, eInventoryType::ALL)) { GameMessages::SendVendorTransactionResult(buyer, buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_FAIL); return; } - inventoryComponent->RemoveItem(costLOT, altCurrencyCost); inventoryComponent->AddItem(lot, count, eLootSourceType::VENDOR); GameMessages::SendVendorTransactionResult(buyer, buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_SUCCESS); diff --git a/dGame/dComponents/ActivityComponent.cpp b/dGame/dComponents/ActivityComponent.cpp index 9f256a3e..8e0c62d3 100644 --- a/dGame/dComponents/ActivityComponent.cpp +++ b/dGame/dComponents/ActivityComponent.cpp @@ -20,7 +20,7 @@ #include "Loot.h" #include "eMissionTaskType.h" #include "eMatchUpdate.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "MessageType/Chat.h" #include "CDCurrencyTableTable.h" @@ -354,10 +354,7 @@ bool ActivityComponent::CheckCost(Entity* player) const { bool ActivityComponent::TakeCost(Entity* player) const { auto* inventoryComponent = player->GetComponent(); - if (CheckCost(player)) { - inventoryComponent->RemoveItem(m_ActivityInfo.optionalCostLOT, m_ActivityInfo.optionalCostCount); - return true; - } else return false; + return CheckCost(player) && inventoryComponent->RemoveItem(m_ActivityInfo.optionalCostLOT, m_ActivityInfo.optionalCostCount, eInventoryType::ALL); } void ActivityComponent::PlayerReady(Entity* player, bool bReady) { @@ -512,7 +509,7 @@ void ActivityInstance::StartZone() { // only make a team if we have more than one participant if (participants.size() > 1) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::CREATE_TEAM); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::CREATE_TEAM); bitStream.Write(leader->GetObjectID()); bitStream.Write(m_Participants.size()); diff --git a/dGame/dComponents/BaseCombatAIComponent.cpp b/dGame/dComponents/BaseCombatAIComponent.cpp index fbe5a382..76228ec7 100644 --- a/dGame/dComponents/BaseCombatAIComponent.cpp +++ b/dGame/dComponents/BaseCombatAIComponent.cpp @@ -767,7 +767,7 @@ void BaseCombatAIComponent::LookAt(const NiPoint3& point) { return; } - m_Parent->SetRotation(NiQuaternion::LookAt(m_Parent->GetPosition(), point)); + m_Parent->SetRotation(QuatUtils::LookAt(m_Parent->GetPosition(), point)); } void BaseCombatAIComponent::SetDisabled(bool value) { diff --git a/dGame/dComponents/CMakeLists.txt b/dGame/dComponents/CMakeLists.txt index e1116895..e82ec360 100644 --- a/dGame/dComponents/CMakeLists.txt +++ b/dGame/dComponents/CMakeLists.txt @@ -77,4 +77,4 @@ target_include_directories(dComponents PUBLIC "." ) target_precompile_headers(dComponents REUSE_FROM dGameBase) -target_link_libraries(dComponents INTERFACE dBehaviors) +target_link_libraries(dComponents INTERFACE dBehaviors PRIVATE glm::glm) diff --git a/dGame/dComponents/CharacterComponent.h b/dGame/dComponents/CharacterComponent.h index 6d52da32..5e7059f3 100644 --- a/dGame/dComponents/CharacterComponent.h +++ b/dGame/dComponents/CharacterComponent.h @@ -622,7 +622,7 @@ private: NiPoint3 m_respawnPos; - NiQuaternion m_respawnRot; + NiQuaternion m_respawnRot = QuatUtils::IDENTITY; std::map m_DroppedLoot; diff --git a/dGame/dComponents/InventoryComponent.cpp b/dGame/dComponents/InventoryComponent.cpp index 4cc0a3de..4b50ece2 100644 --- a/dGame/dComponents/InventoryComponent.cpp +++ b/dGame/dComponents/InventoryComponent.cpp @@ -1279,7 +1279,7 @@ void InventoryComponent::SpawnPet(Item* item) { EntityInfo info{}; info.lot = item->GetLot(); info.pos = m_Parent->GetPosition(); - info.rot = NiQuaternionConstant::IDENTITY; + info.rot = QuatUtils::IDENTITY; info.spawnerID = m_Parent->GetObjectID(); auto* pet = Game::entityManager->CreateEntity(info); diff --git a/dGame/dComponents/ModelComponent.h b/dGame/dComponents/ModelComponent.h index 8f36fa91..f6277db6 100644 --- a/dGame/dComponents/ModelComponent.h +++ b/dGame/dComponents/ModelComponent.h @@ -205,7 +205,7 @@ private: /** * The rotation original of the model */ - NiQuaternion m_OriginalRotation; + NiQuaternion m_OriginalRotation = QuatUtils::IDENTITY; /** * The ID of the user that made the model diff --git a/dGame/dComponents/MovementAIComponent.cpp b/dGame/dComponents/MovementAIComponent.cpp index ea62cd17..30df333b 100644 --- a/dGame/dComponents/MovementAIComponent.cpp +++ b/dGame/dComponents/MovementAIComponent.cpp @@ -83,7 +83,7 @@ void MovementAIComponent::Resume() { m_Paused = false; SetVelocity(m_SavedVelocity); m_SavedVelocity = NiPoint3Constant::ZERO; - SetRotation(NiQuaternion::LookAt(m_Parent->GetPosition(), m_NextWaypoint)); + SetRotation(QuatUtils::LookAt(m_Parent->GetPosition(), m_NextWaypoint)); Game::entityManager->SerializeEntity(m_Parent); } @@ -154,7 +154,7 @@ void MovementAIComponent::Update(const float deltaTime) { m_TimeTravelled = 0.0f; m_TimeToTravel = length / speed; - SetRotation(NiQuaternion::LookAt(source, m_NextWaypoint)); + SetRotation(QuatUtils::LookAt(source, m_NextWaypoint)); } } else { // Check if there are more waypoints in the queue, if so set our next destination to the next waypoint diff --git a/dGame/dComponents/PetComponent.cpp b/dGame/dComponents/PetComponent.cpp index c183fcea..de805e10 100644 --- a/dGame/dComponents/PetComponent.cpp +++ b/dGame/dComponents/PetComponent.cpp @@ -168,7 +168,7 @@ void PetComponent::OnUse(Entity* originator) { const auto originatorPosition = originator->GetPosition(); - m_Parent->SetRotation(NiQuaternion::LookAt(petPosition, originatorPosition)); + m_Parent->SetRotation(QuatUtils::LookAt(petPosition, originatorPosition)); float interactionDistance = m_Parent->GetVar(u"interaction_distance"); if (interactionDistance <= 0) { @@ -177,7 +177,7 @@ void PetComponent::OnUse(Entity* originator) { auto position = originatorPosition; - NiPoint3 forward = NiQuaternion::LookAt(m_Parent->GetPosition(), originator->GetPosition()).GetForwardVector(); + NiPoint3 forward = QuatUtils::Forward(QuatUtils::LookAt(m_Parent->GetPosition(), originator->GetPosition())); forward.y = 0; if (dpWorld::IsLoaded()) { @@ -186,7 +186,7 @@ void PetComponent::OnUse(Entity* originator) { NiPoint3 nearestPoint = dpWorld::GetNavMesh()->NearestPoint(attempt); while (std::abs(nearestPoint.y - petPosition.y) > 4 && interactionDistance > 10) { - const NiPoint3 forward = m_Parent->GetRotation().GetForwardVector(); + const NiPoint3 forward = QuatUtils::Forward(m_Parent->GetRotation()); attempt = originatorPosition + forward * interactionDistance; @@ -200,7 +200,7 @@ void PetComponent::OnUse(Entity* originator) { position = petPosition + forward * interactionDistance; } - auto rotation = NiQuaternion::LookAt(position, petPosition); + auto rotation = QuatUtils::LookAt(position, petPosition); GameMessages::SendNotifyPetTamingMinigame( originator->GetObjectID(), @@ -460,7 +460,7 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) { EntityInfo info{}; info.lot = entry->puzzleModelLot; info.pos = position; - info.rot = NiQuaternionConstant::IDENTITY; + info.rot = QuatUtils::IDENTITY; info.spawnerID = tamer->GetObjectID(); auto* modelEntity = Game::entityManager->CreateEntity(info); @@ -522,7 +522,7 @@ void PetComponent::NotifyTamingBuildSuccess(NiPoint3 position) { ePetTamingNotifyType::NAMINGPET, NiPoint3Constant::ZERO, NiPoint3Constant::ZERO, - NiQuaternionConstant::IDENTITY, + QuatUtils::IDENTITY, UNASSIGNED_SYSTEM_ADDRESS ); @@ -601,7 +601,7 @@ void PetComponent::RequestSetPetName(std::u16string name) { ePetTamingNotifyType::SUCCESS, NiPoint3Constant::ZERO, NiPoint3Constant::ZERO, - NiQuaternionConstant::IDENTITY, + QuatUtils::IDENTITY, UNASSIGNED_SYSTEM_ADDRESS ); @@ -645,7 +645,7 @@ void PetComponent::ClientExitTamingMinigame(bool voluntaryExit) { ePetTamingNotifyType::QUIT, NiPoint3Constant::ZERO, NiPoint3Constant::ZERO, - NiQuaternionConstant::IDENTITY, + QuatUtils::IDENTITY, UNASSIGNED_SYSTEM_ADDRESS ); @@ -696,7 +696,7 @@ void PetComponent::ClientFailTamingMinigame() { ePetTamingNotifyType::FAILED, NiPoint3Constant::ZERO, NiPoint3Constant::ZERO, - NiQuaternionConstant::IDENTITY, + QuatUtils::IDENTITY, UNASSIGNED_SYSTEM_ADDRESS ); diff --git a/dGame/dComponents/PhantomPhysicsComponent.h b/dGame/dComponents/PhantomPhysicsComponent.h index ce8113ec..1d53ce2c 100644 --- a/dGame/dComponents/PhantomPhysicsComponent.h +++ b/dGame/dComponents/PhantomPhysicsComponent.h @@ -175,5 +175,5 @@ private: /** * If this is a respawn volume, the exact rotation an entity will respawn */ - NiQuaternion m_RespawnRot; + NiQuaternion m_RespawnRot = QuatUtils::IDENTITY; }; diff --git a/dGame/dComponents/PhysicsComponent.cpp b/dGame/dComponents/PhysicsComponent.cpp index e7e87287..97546c81 100644 --- a/dGame/dComponents/PhysicsComponent.cpp +++ b/dGame/dComponents/PhysicsComponent.cpp @@ -17,7 +17,7 @@ PhysicsComponent::PhysicsComponent(Entity* parent, int32_t componentId) : Component(parent) { m_Position = NiPoint3Constant::ZERO; - m_Rotation = NiQuaternionConstant::IDENTITY; + m_Rotation = QuatUtils::IDENTITY; m_DirtyPosition = false; CDPhysicsComponentTable* physicsComponentTable = CDClientManager::GetTable(); @@ -81,10 +81,10 @@ dpEntity* PhysicsComponent::CreatePhysicsEntity(eReplicaComponentType type) { toReturn = new dpEntity(m_Parent->GetObjectID(), 1.0f, 12.5f, 20.0f); // Not sure what the real size is } else if (info->physicsAsset == "env\\NG_NinjaGo\\env_ng_gen_gate_chamber_puzzle_ceiling_tile_falling_phantom.hkx") { toReturn = new dpEntity(m_Parent->GetObjectID(), 18.0f, 5.0f, 15.0f); - m_Position += m_Rotation.GetForwardVector() * 7.5f; + m_Position += QuatUtils::Forward(m_Rotation) * 7.5f; } else if (info->physicsAsset == "env\\NG_NinjaGo\\ng_flamejet_brick_phantom.HKX") { toReturn = new dpEntity(m_Parent->GetObjectID(), 1.0f, 1.0f, 12.0f); - m_Position += m_Rotation.GetForwardVector() * 6.0f; + m_Position += QuatUtils::Forward(m_Rotation) * 6.0f; } else if (info->physicsAsset == "env\\Ring_Trigger.hkx") { toReturn = new dpEntity(m_Parent->GetObjectID(), 6.0f, 6.0f, 6.0f); } else if (info->physicsAsset == "env\\vfx_propertyImaginationBall.hkx") { diff --git a/dGame/dComponents/PhysicsComponent.h b/dGame/dComponents/PhysicsComponent.h index f80a51dd..f100b4da 100644 --- a/dGame/dComponents/PhysicsComponent.h +++ b/dGame/dComponents/PhysicsComponent.h @@ -45,7 +45,7 @@ protected: NiPoint3 m_Position; - NiQuaternion m_Rotation; + NiQuaternion m_Rotation = QuatUtils::IDENTITY; bool m_DirtyPosition; diff --git a/dGame/dComponents/PropertyManagementComponent.cpp b/dGame/dComponents/PropertyManagementComponent.cpp index 581e28f3..ccef695f 100644 --- a/dGame/dComponents/PropertyManagementComponent.cpp +++ b/dGame/dComponents/PropertyManagementComponent.cpp @@ -333,7 +333,7 @@ void PropertyManagementComponent::UpdateModelPosition(const LWOOBJID id, const N const auto modelLOT = item->GetLot(); - if (rotation != NiQuaternionConstant::IDENTITY) { + if (rotation != QuatUtils::IDENTITY) { rotation = { rotation.w, rotation.z, rotation.y, rotation.x }; } @@ -516,7 +516,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet GameMessages::SendGetModelsOnProperty(entity->GetObjectID(), GetModels(), UNASSIGNED_SYSTEM_ADDRESS); - GameMessages::SendPlaceModelResponse(entity->GetObjectID(), entity->GetSystemAddress(), NiPoint3Constant::ZERO, LWOOBJID_EMPTY, 16, NiQuaternionConstant::IDENTITY); + GameMessages::SendPlaceModelResponse(entity->GetObjectID(), entity->GetSystemAddress(), NiPoint3Constant::ZERO, LWOOBJID_EMPTY, 16, QuatUtils::IDENTITY); if (spawner != nullptr) { Game::zoneManager->RemoveSpawner(spawner->m_Info.spawnerID); @@ -569,7 +569,7 @@ void PropertyManagementComponent::DeleteModel(const LWOOBJID id, const int delet GameMessages::SendGetModelsOnProperty(entity->GetObjectID(), GetModels(), UNASSIGNED_SYSTEM_ADDRESS); - GameMessages::SendPlaceModelResponse(entity->GetObjectID(), entity->GetSystemAddress(), NiPoint3Constant::ZERO, LWOOBJID_EMPTY, 16, NiQuaternionConstant::IDENTITY); + GameMessages::SendPlaceModelResponse(entity->GetObjectID(), entity->GetSystemAddress(), NiPoint3Constant::ZERO, LWOOBJID_EMPTY, 16, QuatUtils::IDENTITY); if (spawner != nullptr) { Game::zoneManager->RemoveSpawner(spawner->m_Info.spawnerID); diff --git a/dGame/dComponents/RacingControlComponent.cpp b/dGame/dComponents/RacingControlComponent.cpp index 0761dc4a..5f2373f9 100644 --- a/dGame/dComponents/RacingControlComponent.cpp +++ b/dGame/dComponents/RacingControlComponent.cpp @@ -123,7 +123,7 @@ void RacingControlComponent::LoadPlayerVehicle(Entity* player, auto spawnPointEntities = Game::entityManager->GetEntitiesByLOT(4843); auto startPosition = NiPoint3Constant::ZERO; - auto startRotation = NiQuaternionConstant::IDENTITY; + auto startRotation = QuatUtils::IDENTITY; const std::string placementAsString = std::to_string(positionNumber); for (auto entity : spawnPointEntities) { if (!entity) continue; diff --git a/dGame/dComponents/RacingControlComponent.h b/dGame/dComponents/RacingControlComponent.h index 67884d0d..b9f21498 100644 --- a/dGame/dComponents/RacingControlComponent.h +++ b/dGame/dComponents/RacingControlComponent.h @@ -48,7 +48,7 @@ struct RacingPlayerInfo { /** * Rotation that the player will respawn at if they smash their car */ - NiQuaternion respawnRotation; + NiQuaternion respawnRotation = QuatUtils::IDENTITY; /** * The index in the respawn point the player is now at diff --git a/dGame/dComponents/RocketLaunchpadControlComponent.cpp b/dGame/dComponents/RocketLaunchpadControlComponent.cpp index 8fde926b..746a161a 100644 --- a/dGame/dComponents/RocketLaunchpadControlComponent.cpp +++ b/dGame/dComponents/RocketLaunchpadControlComponent.cpp @@ -17,7 +17,7 @@ #include "dServer.h" #include "BitStreamUtils.h" #include "eObjectWorldState.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "MessageType/Master.h" RocketLaunchpadControlComponent::RocketLaunchpadControlComponent(Entity* parent, int rocketId) : Component(parent) { @@ -137,7 +137,7 @@ LWOCLONEID RocketLaunchpadControlComponent::GetSelectedCloneId(LWOOBJID player) void RocketLaunchpadControlComponent::TellMasterToPrepZone(int zoneID) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::PREP_ZONE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::PREP_ZONE); bitStream.Write(zoneID); Game::server->SendToMaster(bitStream); } diff --git a/dGame/dComponents/SkillComponent.cpp b/dGame/dComponents/SkillComponent.cpp index e16e3a2e..4909b43f 100644 --- a/dGame/dComponents/SkillComponent.cpp +++ b/dGame/dComponents/SkillComponent.cpp @@ -23,7 +23,7 @@ #include "DoClientProjectileImpact.h" #include "CDClientManager.h" #include "CDSkillBehaviorTable.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "MessageType/Client.h" ProjectileSyncEntry::ProjectileSyncEntry() { @@ -316,7 +316,7 @@ SkillExecutionResult SkillComponent::CalculateBehavior( start.originatorRot = originator->GetRotation(); } - if (rotationOverride != NiQuaternionConstant::IDENTITY) { + if (rotationOverride != QuatUtils::IDENTITY) { start.originatorRot = rotationOverride; } //start.optionalTargetID = target; @@ -326,7 +326,7 @@ SkillExecutionResult SkillComponent::CalculateBehavior( // Write message RakNet::BitStream message; - BitStreamUtils::WriteHeader(message, eConnectionType::CLIENT, MessageType::Client::GAME_MSG); + BitStreamUtils::WriteHeader(message, ServiceType::CLIENT, MessageType::Client::GAME_MSG); message.Write(this->m_Parent->GetObjectID()); start.Serialize(message); @@ -457,7 +457,7 @@ void SkillComponent::SyncProjectileCalculation(const ProjectileSyncEntry& entry) RakNet::BitStream message; - BitStreamUtils::WriteHeader(message, eConnectionType::CLIENT, MessageType::Client::GAME_MSG); + BitStreamUtils::WriteHeader(message, ServiceType::CLIENT, MessageType::Client::GAME_MSG); message.Write(this->m_Parent->GetObjectID()); projectileImpact.Serialize(message); diff --git a/dGame/dComponents/SkillComponent.h b/dGame/dComponents/SkillComponent.h index b7cd7786..a5483ee5 100644 --- a/dGame/dComponents/SkillComponent.h +++ b/dGame/dComponents/SkillComponent.h @@ -129,7 +129,7 @@ public: * @param optionalOriginatorID change the originator of the skill * @return if the case succeeded */ - bool CastSkill(const uint32_t skillId, LWOOBJID target = LWOOBJID_EMPTY, const LWOOBJID optionalOriginatorID = LWOOBJID_EMPTY, const int32_t castType = 0, const NiQuaternion rotationOverride = NiQuaternionConstant::IDENTITY); + bool CastSkill(const uint32_t skillId, LWOOBJID target = LWOOBJID_EMPTY, const LWOOBJID optionalOriginatorID = LWOOBJID_EMPTY, const int32_t castType = 0, const NiQuaternion rotationOverride = QuatUtils::IDENTITY); /** * Initializes a server-side skill calculation. @@ -141,7 +141,7 @@ public: * @param originatorOverride an override for the originator of the skill calculation * @return the result of the skill calculation */ - SkillExecutionResult CalculateBehavior(uint32_t skillId, uint32_t behaviorId, LWOOBJID target, bool ignoreTarget = false, bool clientInitalized = false, LWOOBJID originatorOverride = LWOOBJID_EMPTY, const int32_t castType = 0, const NiQuaternion rotationOverride = NiQuaternionConstant::IDENTITY); + SkillExecutionResult CalculateBehavior(uint32_t skillId, uint32_t behaviorId, LWOOBJID target, bool ignoreTarget = false, bool clientInitalized = false, LWOOBJID originatorOverride = LWOOBJID_EMPTY, const int32_t castType = 0, const NiQuaternion rotationOverride = QuatUtils::IDENTITY); /** * Register a server-side projectile. diff --git a/dGame/dComponents/TriggerComponent.cpp b/dGame/dComponents/TriggerComponent.cpp index a9d00b15..f2d47716 100644 --- a/dGame/dComponents/TriggerComponent.cpp +++ b/dGame/dComponents/TriggerComponent.cpp @@ -17,6 +17,8 @@ #include "EntityManager.h" #include "MovementAIComponent.h" +#include + TriggerComponent::TriggerComponent(Entity* parent, const std::string triggerInfo) : Component(parent) { m_Parent = parent; m_Trigger = nullptr; @@ -240,10 +242,9 @@ void TriggerComponent::HandleMoveObject(Entity* targetEntity, std::vector argArray) { if (argArray.size() <= 2) return; - const NiPoint3 vector = GeneralUtils::TryParse(argArray).value_or(NiPoint3Constant::ZERO); + const auto vector = GeneralUtils::TryParse(argArray).value_or(glm::zero()); - NiQuaternion rotation = NiQuaternion::FromEulerAngles(vector); - targetEntity->SetRotation(rotation); + targetEntity->SetRotation(glm::quat(vector)); } void TriggerComponent::HandlePushObject(Entity* targetEntity, std::vector argArray) { diff --git a/dGame/dComponents/VendorComponent.cpp b/dGame/dComponents/VendorComponent.cpp index b4a5f05c..b6c89a50 100644 --- a/dGame/dComponents/VendorComponent.cpp +++ b/dGame/dComponents/VendorComponent.cpp @@ -164,10 +164,17 @@ void VendorComponent::Buy(Entity* buyer, LOT lot, uint32_t count) { return; } } + + bool success = true; for (const auto& [crafintCurrencyLOT, crafintCurrencyCount]: craftingCurrencies) { - inventoryComponent->RemoveItem(crafintCurrencyLOT, crafintCurrencyCount * count); + success = inventoryComponent->RemoveItem(crafintCurrencyLOT, crafintCurrencyCount * count, eInventoryType::ALL); + if (!success) break; } + if (!success) { + GameMessages::SendVendorTransactionResult(buyer, buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_FAIL); + return; + } float buyScalar = GetBuyScalar(); const auto coinCost = static_cast(std::floor((itemComp.baseValue * buyScalar) * count)); @@ -184,7 +191,7 @@ void VendorComponent::Buy(Entity* buyer, LOT lot, uint32_t count) { GameMessages::SendVendorTransactionResult(buyer, buyer->GetSystemAddress(), eVendorTransactionResult::PURCHASE_FAIL); return; } - inventoryComponent->RemoveItem(itemComp.currencyLOT, altCurrencyCost); + inventoryComponent->RemoveItem(itemComp.currencyLOT, altCurrencyCost, eInventoryType::ALL); } character->SetCoins(character->GetCoins() - (coinCost), eLootSourceType::VENDOR); diff --git a/dGame/dEntity/EntityInfo.h b/dGame/dEntity/EntityInfo.h index 049c5ce3..e16c315d 100644 --- a/dGame/dEntity/EntityInfo.h +++ b/dGame/dEntity/EntityInfo.h @@ -33,7 +33,7 @@ struct EntityInfo { LWOOBJID id; LOT lot; NiPoint3 pos; - NiQuaternion rot; + NiQuaternion rot = QuatUtils::IDENTITY; std::vector settings; std::vector networkSettings; float scale; diff --git a/dGame/dGameMessages/EchoStartSkill.h b/dGame/dGameMessages/EchoStartSkill.h index c2c6b1d4..0afef3f4 100644 --- a/dGame/dGameMessages/EchoStartSkill.h +++ b/dGame/dGameMessages/EchoStartSkill.h @@ -15,11 +15,11 @@ public: iCastType = 0; lastClickedPosit = NiPoint3Constant::ZERO; optionalTargetID = LWOOBJID_EMPTY; - originatorRot = NiQuaternionConstant::IDENTITY; + originatorRot = QuatUtils::IDENTITY; uiSkillHandle = 0; } - EchoStartSkill(LWOOBJID _optionalOriginatorID, std::string _sBitStream, TSkillID _skillID, bool _bUsedMouse = false, float _fCasterLatency = 0.0f, int32_t _iCastType = 0, NiPoint3 _lastClickedPosit = NiPoint3Constant::ZERO, LWOOBJID _optionalTargetID = LWOOBJID_EMPTY, NiQuaternion _originatorRot = NiQuaternionConstant::IDENTITY, uint32_t _uiSkillHandle = 0) { + EchoStartSkill(LWOOBJID _optionalOriginatorID, std::string _sBitStream, TSkillID _skillID, bool _bUsedMouse = false, float _fCasterLatency = 0.0f, int32_t _iCastType = 0, NiPoint3 _lastClickedPosit = NiPoint3Constant::ZERO, LWOOBJID _optionalTargetID = LWOOBJID_EMPTY, NiQuaternion _originatorRot = QuatUtils::IDENTITY, uint32_t _uiSkillHandle = 0) { bUsedMouse = _bUsedMouse; fCasterLatency = _fCasterLatency; iCastType = _iCastType; @@ -58,8 +58,8 @@ public: stream.Write(optionalTargetID != LWOOBJID_EMPTY); if (optionalTargetID != LWOOBJID_EMPTY) stream.Write(optionalTargetID); - stream.Write(originatorRot != NiQuaternionConstant::IDENTITY); - if (originatorRot != NiQuaternionConstant::IDENTITY) stream.Write(originatorRot); + stream.Write(originatorRot != QuatUtils::IDENTITY); + if (originatorRot != QuatUtils::IDENTITY) stream.Write(originatorRot); uint32_t sBitStreamLength = sBitStream.length(); stream.Write(sBitStreamLength); @@ -121,7 +121,7 @@ public: NiPoint3 lastClickedPosit; LWOOBJID optionalOriginatorID; LWOOBJID optionalTargetID; - NiQuaternion originatorRot; + NiQuaternion originatorRot = QuatUtils::IDENTITY; std::string sBitStream; TSkillID skillID; uint32_t uiSkillHandle; diff --git a/dGame/dGameMessages/GameMessageHandler.cpp b/dGame/dGameMessages/GameMessageHandler.cpp index 60af60c7..eae01e56 100644 --- a/dGame/dGameMessages/GameMessageHandler.cpp +++ b/dGame/dGameMessages/GameMessageHandler.cpp @@ -32,7 +32,7 @@ #include "EchoSyncSkill.h" #include "eMissionTaskType.h" #include "eReplicaComponentType.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "MessageType/Game.h" #include "ePlayerFlag.h" #include "dConfig.h" @@ -353,7 +353,7 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream& inStream, const System if (success) { //Broadcast our startSkill: RakNet::BitStream bitStreamLocal; - BitStreamUtils::WriteHeader(bitStreamLocal, eConnectionType::CLIENT, MessageType::Client::GAME_MSG); + BitStreamUtils::WriteHeader(bitStreamLocal, ServiceType::CLIENT, MessageType::Client::GAME_MSG); bitStreamLocal.Write(entity->GetObjectID()); EchoStartSkill echoStartSkill; @@ -375,7 +375,7 @@ void GameMessageHandler::HandleMessage(RakNet::BitStream& inStream, const System case MessageType::Game::SYNC_SKILL: { RakNet::BitStream bitStreamLocal; - BitStreamUtils::WriteHeader(bitStreamLocal, eConnectionType::CLIENT, MessageType::Client::GAME_MSG); + BitStreamUtils::WriteHeader(bitStreamLocal, ServiceType::CLIENT, MessageType::Client::GAME_MSG); bitStreamLocal.Write(entity->GetObjectID()); SyncSkill sync = SyncSkill(inStream); // inStream replaced &bitStream diff --git a/dGame/dGameMessages/GameMessages.cpp b/dGame/dGameMessages/GameMessages.cpp index 61061771..08b1817e 100644 --- a/dGame/dGameMessages/GameMessages.cpp +++ b/dGame/dGameMessages/GameMessages.cpp @@ -40,7 +40,7 @@ #include "eQuickBuildFailReason.h" #include "eControlScheme.h" #include "eStateChangeType.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "ePlayerFlag.h" #include @@ -389,7 +389,7 @@ void GameMessages::SendPlatformResync(Entity* entity, const SystemAddress& sysAd float fMoveTimeElapsed = 0.0f; float fPercentBetweenPoints = 0.0f; NiPoint3 ptUnexpectedLocation = NiPoint3Constant::ZERO; - NiQuaternion qUnexpectedRotation = NiQuaternionConstant::IDENTITY; + NiQuaternion qUnexpectedRotation = QuatUtils::IDENTITY; bitStream.Write(bReverse); bitStream.Write(bStopAtDesiredWaypoint); @@ -406,8 +406,8 @@ void GameMessages::SendPlatformResync(Entity* entity, const SystemAddress& sysAd bitStream.Write(ptUnexpectedLocation.y); bitStream.Write(ptUnexpectedLocation.z); - bitStream.Write(qUnexpectedRotation != NiQuaternionConstant::IDENTITY); - if (qUnexpectedRotation != NiQuaternionConstant::IDENTITY) { + bitStream.Write(qUnexpectedRotation != QuatUtils::IDENTITY); + if (qUnexpectedRotation != QuatUtils::IDENTITY) { bitStream.Write(qUnexpectedRotation.x); bitStream.Write(qUnexpectedRotation.y); bitStream.Write(qUnexpectedRotation.z); @@ -1181,7 +1181,7 @@ void GameMessages::SendPlayerReachedRespawnCheckpoint(Entity* entity, const NiPo bitStream.Write(position.y); bitStream.Write(position.z); - const bool bIsNotIdentity = rotation != NiQuaternionConstant::IDENTITY; + const bool bIsNotIdentity = rotation != QuatUtils::IDENTITY; bitStream.Write(bIsNotIdentity); if (bIsNotIdentity) { @@ -2129,8 +2129,8 @@ void GameMessages::SendPlaceModelResponse(LWOOBJID objectId, const SystemAddress bitStream.Write(response); } - bitStream.Write(rotation != NiQuaternionConstant::IDENTITY); - if (rotation != NiQuaternionConstant::IDENTITY) { + bitStream.Write(rotation != QuatUtils::IDENTITY); + if (rotation != QuatUtils::IDENTITY) { bitStream.Write(response); } @@ -2208,7 +2208,7 @@ void GameMessages::HandleUnUseModel(RakNet::BitStream& inStream, Entity* entity, if (unknown) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::BLUEPRINT_SAVE_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::BLUEPRINT_SAVE_RESPONSE); bitStream.Write(LWOOBJID_EMPTY); //always zero so that a check on the client passes bitStream.Write(eBlueprintSaveResponseType::PlacementFailed); // Sending a non-zero error code here prevents the client from deleting its in progress build for some reason? bitStream.Write(0); @@ -2395,13 +2395,13 @@ void GameMessages::HandlePlacePropertyModel(RakNet::BitStream& inStream, Entity* inStream.Read(model); - PropertyManagementComponent::Instance()->UpdateModelPosition(model, NiPoint3Constant::ZERO, NiQuaternionConstant::IDENTITY); + PropertyManagementComponent::Instance()->UpdateModelPosition(model, NiPoint3Constant::ZERO, QuatUtils::IDENTITY); } void GameMessages::HandleUpdatePropertyModel(RakNet::BitStream& inStream, Entity* entity, const SystemAddress& sysAddr) { LWOOBJID model; NiPoint3 position; - NiQuaternion rotation = NiQuaternionConstant::IDENTITY; + NiQuaternion rotation = QuatUtils::IDENTITY; inStream.Read(model); inStream.Read(position); @@ -2460,7 +2460,7 @@ void GameMessages::HandleBBBLoadItemRequest(RakNet::BitStream& inStream, Entity* void GameMessages::SendBlueprintLoadItemResponse(const SystemAddress& sysAddr, bool success, LWOOBJID oldItemId, LWOOBJID newItemId) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::BLUEPRINT_LOAD_RESPONSE_ITEMID); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::BLUEPRINT_LOAD_RESPONSE_ITEMID); bitStream.Write(success); bitStream.Write(oldItemId); bitStream.Write(newItemId); @@ -2652,7 +2652,7 @@ void GameMessages::HandleBBBSaveRequest(RakNet::BitStream& inStream, Entity* ent uint32_t sd0Size{}; for (const auto& chunk : newSd0) sd0Size += chunk.size(); CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::BLUEPRINT_SAVE_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::BLUEPRINT_SAVE_RESPONSE); bitStream.Write(localId); bitStream.Write(eBlueprintSaveResponseType::EverythingWorked); bitStream.Write(1); @@ -3400,7 +3400,7 @@ void GameMessages::SendNotifyPetTamingMinigame(LWOOBJID objectId, LWOOBJID petId bitStream.Write(petsDestPos); bitStream.Write(telePos); - const bool hasDefault = teleRot != NiQuaternionConstant::IDENTITY; + const bool hasDefault = teleRot != QuatUtils::IDENTITY; bitStream.Write(hasDefault); if (hasDefault) bitStream.Write(teleRot); @@ -4823,11 +4823,10 @@ void GameMessages::HandleBuybackFromVendor(RakNet::BitStream& inStream, Entity* if (Inventory::IsValidItem(itemComp.currencyLOT)) { const uint32_t altCurrencyCost = std::floor(itemComp.altCurrencyCost * sellScalar) * count; - if (inv->GetLotCount(itemComp.currencyLOT) < altCurrencyCost) { + if (inv->GetLotCount(itemComp.currencyLOT) < altCurrencyCost || !inv->RemoveItem(itemComp.currencyLOT, altCurrencyCost, eInventoryType::ALL)) { GameMessages::SendVendorTransactionResult(entity, sysAddr, eVendorTransactionResult::PURCHASE_FAIL); return; } - inv->RemoveItem(itemComp.currencyLOT, altCurrencyCost); } //inv->RemoveItem(count, -1, iObjID); @@ -5508,10 +5507,18 @@ void GameMessages::HandleModularBuildFinish(RakNet::BitStream& inStream, Entity* modules += u"1:" + (modToStr); if (k + 1 != count) modules += u"+"; + bool hasItem = false; if (temp->GetLotCount(mod) > 0) { - inv->RemoveItem(mod, 1, TEMP_MODELS); + hasItem = inv->RemoveItem(mod, 1, TEMP_MODELS); } else { - inv->RemoveItem(mod, 1); + hasItem = inv->RemoveItem(mod, 1, eInventoryType::ALL); + } + + if (!hasItem) { + LOG("Player (%llu) attempted to finish a modular build without having all the required parts.", character->GetObjectID()); + GameMessages::SendFinishArrangingWithItem(character, entity->GetObjectID()); // kick them from modular build + GameMessages::SendModularBuildEnd(character); // i dont know if this does anything but DLUv2 did it + return; } // Doing this check for 1 singular mission that needs to know when you've swapped every part out during a car modular build. diff --git a/dGame/dGameMessages/GameMessages.h b/dGame/dGameMessages/GameMessages.h index a64f2a18..c4dbb1d3 100644 --- a/dGame/dGameMessages/GameMessages.h +++ b/dGame/dGameMessages/GameMessages.h @@ -18,7 +18,6 @@ class AMFBaseValue; class AMFArrayValue; class Entity; class Item; -class NiQuaternion; class User; class Leaderboard; class PropertySelectQueryProperty; @@ -765,7 +764,7 @@ namespace GameMessages { void Handle(Entity& entity, const SystemAddress& sysAddr) override; NiPoint3 target{}; - NiQuaternion rotation{}; + NiQuaternion rotation = QuatUtils::IDENTITY; }; struct ChildLoaded : public GameMsg { diff --git a/dGame/dGameMessages/StartSkill.h b/dGame/dGameMessages/StartSkill.h index 15791039..91e35572 100644 --- a/dGame/dGameMessages/StartSkill.h +++ b/dGame/dGameMessages/StartSkill.h @@ -18,11 +18,11 @@ public: iCastType = 0; lastClickedPosit = NiPoint3Constant::ZERO; optionalTargetID = LWOOBJID_EMPTY; - originatorRot = NiQuaternionConstant::IDENTITY; + originatorRot = QuatUtils::IDENTITY; uiSkillHandle = 0; } - StartSkill(LWOOBJID _optionalOriginatorID, std::string _sBitStream, TSkillID _skillID, bool _bUsedMouse = false, LWOOBJID _consumableItemID = LWOOBJID_EMPTY, float _fCasterLatency = 0.0f, int32_t _iCastType = 0, NiPoint3 _lastClickedPosit = NiPoint3Constant::ZERO, LWOOBJID _optionalTargetID = LWOOBJID_EMPTY, NiQuaternion _originatorRot = NiQuaternionConstant::IDENTITY, uint32_t _uiSkillHandle = 0) { + StartSkill(LWOOBJID _optionalOriginatorID, std::string _sBitStream, TSkillID _skillID, bool _bUsedMouse = false, LWOOBJID _consumableItemID = LWOOBJID_EMPTY, float _fCasterLatency = 0.0f, int32_t _iCastType = 0, NiPoint3 _lastClickedPosit = NiPoint3Constant::ZERO, LWOOBJID _optionalTargetID = LWOOBJID_EMPTY, NiQuaternion _originatorRot = QuatUtils::IDENTITY, uint32_t _uiSkillHandle = 0) { bUsedMouse = _bUsedMouse; consumableItemID = _consumableItemID; fCasterLatency = _fCasterLatency; @@ -65,8 +65,8 @@ public: stream.Write(optionalTargetID != LWOOBJID_EMPTY); if (optionalTargetID != LWOOBJID_EMPTY) stream.Write(optionalTargetID); - stream.Write(originatorRot != NiQuaternionConstant::IDENTITY); - if (originatorRot != NiQuaternionConstant::IDENTITY) stream.Write(originatorRot); + stream.Write(originatorRot != QuatUtils::IDENTITY); + if (originatorRot != QuatUtils::IDENTITY) stream.Write(originatorRot); uint32_t sBitStreamLength = sBitStream.length(); stream.Write(sBitStreamLength); @@ -133,7 +133,7 @@ public: NiPoint3 lastClickedPosit{}; LWOOBJID optionalOriginatorID{}; LWOOBJID optionalTargetID{}; - NiQuaternion originatorRot{}; + NiQuaternion originatorRot = QuatUtils::IDENTITY; std::string sBitStream = ""; TSkillID skillID = 0; uint32_t uiSkillHandle = 0; diff --git a/dGame/dInventory/Item.cpp b/dGame/dInventory/Item.cpp index a552eddf..ca93cd9a 100644 --- a/dGame/dInventory/Item.cpp +++ b/dGame/dInventory/Item.cpp @@ -289,11 +289,10 @@ bool Item::Consume() { GameMessages::SendUseItemResult(inventory->GetComponent()->GetParent(), lot, success); - if (success) { + const auto myLot = this->lot; + if (success && inventory->GetComponent()->RemoveItem(lot, 1, eInventoryType::ALL)) { // Save this because if this is the last item in the inventory // we may delete ourself (lol) - const auto myLot = this->lot; - inventory->GetComponent()->RemoveItem(lot, 1); auto* missionComponent = inventory->GetComponent()->GetParent()->GetComponent(); if (missionComponent) missionComponent->Progress(eMissionTaskType::GATHER, myLot, LWOOBJID_EMPTY, "", -1); } diff --git a/dGame/dMission/Mission.cpp b/dGame/dMission/Mission.cpp index e8d2146e..ec430f3e 100644 --- a/dGame/dMission/Mission.cpp +++ b/dGame/dMission/Mission.cpp @@ -483,7 +483,7 @@ void Mission::YieldRewards() { // If a mission rewards zero of an item, make it reward 1. auto count = pair.second > 0 ? pair.second : 1; - + LOG("Player %llu is receiving %i of item %i from repeatable mission %i", entity->GetObjectID(), count, pair.first, info.id); inventoryComponent->AddItem(pair.first, count, IsMission() ? eLootSourceType::MISSION : eLootSourceType::ACHIEVEMENT); } @@ -511,7 +511,7 @@ void Mission::YieldRewards() { // If a mission rewards zero of an item, make it reward 1. auto count = pair.second > 0 ? pair.second : 1; - + LOG("Player %llu is receiving %i of item %i from mission %i", entity->GetObjectID(), count, pair.first, info.id); inventoryComponent->AddItem(pair.first, count, IsMission() ? eLootSourceType::MISSION : eLootSourceType::ACHIEVEMENT); } diff --git a/dGame/dPropertyBehaviors/Strip.cpp b/dGame/dPropertyBehaviors/Strip.cpp index 788e3285..22ef95f9 100644 --- a/dGame/dPropertyBehaviors/Strip.cpp +++ b/dGame/dPropertyBehaviors/Strip.cpp @@ -139,7 +139,7 @@ void Strip::Spawn(LOT lot, Entity& entity) { EntityInfo info{}; info.lot = lot; info.pos = entity.GetPosition(); - info.rot = NiQuaternionConstant::IDENTITY; + info.rot = QuatUtils::IDENTITY; info.spawnerID = entity.GetObjectID(); auto* const spawnedEntity = Game::entityManager->CreateEntity(info, nullptr, &entity); spawnedEntity->AddToGroup("SpawnedPropertyEnemies"); diff --git a/dGame/dUtilities/Loot.cpp b/dGame/dUtilities/Loot.cpp index 853ebd01..5cbdf2d4 100644 --- a/dGame/dUtilities/Loot.cpp +++ b/dGame/dUtilities/Loot.cpp @@ -129,6 +129,10 @@ std::unordered_map Loot::RollLootMatrix(Entity* player, uint32_t m } } + for (const auto& drop : drops) { + LOG("Player %llu has rolled %i of item %i from loot matrix %i", player->GetObjectID(), drop.second, drop.first, matrixIndex); + } + return drops; } diff --git a/dGame/dUtilities/Mail.cpp b/dGame/dUtilities/Mail.cpp index 2e807c73..5ab82f61 100644 --- a/dGame/dUtilities/Mail.cpp +++ b/dGame/dUtilities/Mail.cpp @@ -25,7 +25,7 @@ #include "WorldConfig.h" #include "eMissionTaskType.h" #include "eReplicaComponentType.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "User.h" #include "StringifiedEnum.h" @@ -106,7 +106,7 @@ namespace Mail { // Remove coins and items from the sender player->GetCharacter()->SetCoins(player->GetCharacter()->GetCoins() - mailCost, eLootSourceType::MAIL); if (inventoryComponent && hasAttachment && item) { - removeSuccess = inventoryComponent->RemoveItem(mailInfo.itemLOT, mailInfo.itemCount, INVALID, true); + removeSuccess = inventoryComponent->RemoveItem(mailInfo.itemLOT, mailInfo.itemCount, ALL, true); auto* missionComponent = player->GetComponent(); if (missionComponent && removeSuccess) missionComponent->Progress(eMissionTaskType::GATHER, mailInfo.itemLOT, LWOOBJID_EMPTY, "", -mailInfo.itemCount); } diff --git a/dGame/dUtilities/Mail.h b/dGame/dUtilities/Mail.h index 059b28b1..9c83025f 100644 --- a/dGame/dUtilities/Mail.h +++ b/dGame/dUtilities/Mail.h @@ -109,7 +109,7 @@ namespace Mail { Entity* player = nullptr; MailLUBitStream() = default; - MailLUBitStream(eMessageID _messageID) : LUBitStream(eConnectionType::CLIENT, MessageType::Client::MAIL), messageID{_messageID} {}; + MailLUBitStream(eMessageID _messageID) : LUBitStream(ServiceType::CLIENT, MessageType::Client::MAIL), messageID{_messageID} {}; virtual void Serialize(RakNet::BitStream& bitStream) const override; virtual bool Deserialize(RakNet::BitStream& bitStream) override; diff --git a/dGame/dUtilities/Preconditions.cpp b/dGame/dUtilities/Preconditions.cpp index 118d9037..0c322987 100644 --- a/dGame/dUtilities/Preconditions.cpp +++ b/dGame/dUtilities/Preconditions.cpp @@ -130,9 +130,7 @@ bool Precondition::CheckValue(Entity* player, const uint32_t value, bool evaluat case PreconditionType::HasItem: if (evaluateCosts) // As far as I know this is only used for quickbuilds, and removal shouldn't actually be handled here. { - inventoryComponent->RemoveItem(value, count); - - return true; + return inventoryComponent->RemoveItem(value, count, eInventoryType::ALL); } return inventoryComponent->GetLotCount(value) >= count; diff --git a/dGame/dUtilities/SlashCommandHandler.cpp b/dGame/dUtilities/SlashCommandHandler.cpp index 904509a6..f65fae32 100644 --- a/dGame/dUtilities/SlashCommandHandler.cpp +++ b/dGame/dUtilities/SlashCommandHandler.cpp @@ -153,7 +153,7 @@ void SlashCommandHandler::SendAnnouncement(const std::string& title, const std:: //Notify chat about it CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::GM_ANNOUNCE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::GM_ANNOUNCE); bitStream.Write(title.size()); for (auto character : title) { diff --git a/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp b/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp index afbceaf3..6963ebff 100644 --- a/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp +++ b/dGame/dUtilities/SlashCommands/DEVGMCommands.cpp @@ -507,7 +507,7 @@ namespace DEVGMCommands { void ShutdownUniverse(Entity* entity, const SystemAddress& sysAddr, const std::string args) { //Tell the master server that we're going to be shutting down whole "universe": CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::SHUTDOWN_UNIVERSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::SHUTDOWN_UNIVERSE); Game::server->SendToMaster(bitStream); ChatPackets::SendSystemMessage(sysAddr, u"Sent universe shutdown notification to master."); @@ -649,7 +649,7 @@ namespace DEVGMCommands { if (havokVehiclePhysicsComponent) { havokVehiclePhysicsComponent->SetPosition(pos); Game::entityManager->SerializeEntity(possassableEntity); - } else GameMessages::SendTeleport(possassableEntity->GetObjectID(), pos, NiQuaternion(), sysAddr); + } else GameMessages::SendTeleport(possassableEntity->GetObjectID(), pos, QuatUtils::IDENTITY, sysAddr); } } } @@ -660,7 +660,7 @@ namespace DEVGMCommands { const auto characters = Game::entityManager->GetEntitiesByComponent(eReplicaComponentType::CHARACTER); for (auto* character : characters) { - GameMessages::SendTeleport(character->GetObjectID(), pos, NiQuaternion(), character->GetSystemAddress()); + GameMessages::SendTeleport(character->GetObjectID(), pos, QuatUtils::IDENTITY, character->GetSystemAddress()); } } @@ -815,7 +815,7 @@ namespace DEVGMCommands { // Set the position to the generated random position plus the player position. This will // spawn the entity in a circle around the player. As you get further from the player, the angle chosen will get less accurate. info.pos = playerPosition + NiPoint3(cos(randomAngle) * randomRadius, 0.0f, sin(randomAngle) * randomRadius); - info.rot = NiQuaternion(); + info.rot = QuatUtils::IDENTITY; auto newEntity = Game::entityManager->CreateEntity(info); if (newEntity == nullptr) { diff --git a/dGame/dUtilities/SlashCommands/GMGreaterThanZeroCommands.cpp b/dGame/dUtilities/SlashCommands/GMGreaterThanZeroCommands.cpp index 5c710c09..b31291fe 100644 --- a/dGame/dUtilities/SlashCommands/GMGreaterThanZeroCommands.cpp +++ b/dGame/dUtilities/SlashCommands/GMGreaterThanZeroCommands.cpp @@ -197,7 +197,7 @@ namespace GMGreaterThanZeroCommands { //Notify chat about it CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::GM_MUTE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::GM_MUTE); bitStream.Write(characterId); bitStream.Write(expire); diff --git a/dGame/dUtilities/VanityUtilities.h b/dGame/dUtilities/VanityUtilities.h index 8044fb92..2afd4a6b 100644 --- a/dGame/dUtilities/VanityUtilities.h +++ b/dGame/dUtilities/VanityUtilities.h @@ -8,7 +8,7 @@ struct VanityObjectLocation { float m_Chance = 1.0f; NiPoint3 m_Position; - NiQuaternion m_Rotation; + NiQuaternion m_Rotation = QuatUtils::IDENTITY; float m_Scale = 1.0f; }; diff --git a/dMasterServer/InstanceManager.cpp b/dMasterServer/InstanceManager.cpp index 7dba4802..2a402f87 100644 --- a/dMasterServer/InstanceManager.cpp +++ b/dMasterServer/InstanceManager.cpp @@ -9,7 +9,7 @@ #include "CDZoneTableTable.h" #include "MasterPackets.h" #include "BitStreamUtils.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "MessageType/Master.h" #include "Start.h" @@ -172,7 +172,7 @@ void InstanceManager::RequestAffirmation(const InstancePtr& instance, const Pend CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::AFFIRM_TRANSFER_REQUEST); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::AFFIRM_TRANSFER_REQUEST); bitStream.Write(request.id); @@ -343,7 +343,7 @@ bool Instance::GetShutdownComplete() const { void Instance::Shutdown() { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::SHUTDOWN); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::SHUTDOWN); Game::server->Send(bitStream, this->m_SysAddr, false); diff --git a/dMasterServer/MasterServer.cpp b/dMasterServer/MasterServer.cpp index 52bc0eac..38abdc71 100644 --- a/dMasterServer/MasterServer.cpp +++ b/dMasterServer/MasterServer.cpp @@ -23,7 +23,7 @@ #include "dServer.h" #include "AssetManager.h" #include "BinaryPathFinder.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "MessageType/Master.h" //RakNet includes: @@ -343,7 +343,7 @@ int main(int argc, char** argv) { int res = GenerateBCryptPassword(!cfgPassword.empty() ? cfgPassword : "3.25DARKFLAME1", 13, salt, hash); assert(res == 0); - Game::server = new dServer(ourIP, ourPort, 0, maxClients, true, false, Game::logger, "", 0, ServerType::Master, Game::config, &Game::lastSignal, hash); + Game::server = new dServer(ourIP, ourPort, 0, maxClients, true, false, Game::logger, "", 0, ServiceType::MASTER, Game::config, &Game::lastSignal, hash); std::string master_server_ip = "localhost"; const auto masterServerIPString = Game::config->GetValue("master_ip"); @@ -530,7 +530,7 @@ void HandlePacket(Packet* packet) { if (packet->length < 4) return; - if (static_cast(packet->data[1]) == eConnectionType::MASTER) { + if (static_cast(packet->data[1]) == ServiceType::MASTER) { switch (static_cast(packet->data[3])) { case MessageType::Master::REQUEST_PERSISTENT_ID: { LOG("A persistent ID req"); @@ -592,7 +592,7 @@ void HandlePacket(Packet* packet) { uint32_t theirPort = 0; uint32_t theirZoneID = 0; uint32_t theirInstanceID = 0; - ServerType theirServerType; + ServiceType theirServerType; LUString theirIP; inStream.Read(theirPort); @@ -601,10 +601,10 @@ void HandlePacket(Packet* packet) { inStream.Read(theirServerType); inStream.Read(theirIP); - if (theirServerType == ServerType::World) { + switch (theirServerType) { + case ServiceType::WORLD: if (!Game::im->IsPortInUse(theirPort)) { auto in = std::make_unique(theirIP.string, theirPort, theirZoneID, theirInstanceID, 0, 12, 12); - in->SetSysAddr(packet->systemAddress); Game::im->AddInstance(in); } else { @@ -613,14 +613,16 @@ void HandlePacket(Packet* packet) { instance->SetSysAddr(packet->systemAddress); } } - } - - if (theirServerType == ServerType::Chat) { + break; + case ServiceType::CHAT: chatServerMasterPeerSysAddr = packet->systemAddress; - } - - if (theirServerType == ServerType::Auth) { - authServerMasterPeerSysAddr = packet->systemAddress; + break; + case ServiceType::AUTH: + authServerMasterPeerSysAddr = packet->systemAddress; + break; + default: + // We just ignore any other server type + break; } LOG("Received %s server info, instance: %i port: %i", StringifiedEnum::ToString(theirServerType).data(), theirInstanceID, theirPort); @@ -640,7 +642,7 @@ void HandlePacket(Packet* packet) { activeSessions.erase(it.first); CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::NEW_SESSION_ALERT); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::NEW_SESSION_ALERT); bitStream.Write(sessionKey); bitStream.Write(username); SEND_PACKET_BROADCAST; @@ -662,7 +664,7 @@ void HandlePacket(Packet* packet) { for (auto key : activeSessions) { if (key.second == username.GetAsString()) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::SESSION_KEY_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::SESSION_KEY_RESPONSE); bitStream.Write(key.first); bitStream.Write(username); Game::server->Send(bitStream, packet->systemAddress, false); @@ -873,7 +875,7 @@ int ShutdownSequence(int32_t signal) { { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::SHUTDOWN); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::SHUTDOWN); Game::server->Send(bitStream, UNASSIGNED_SYSTEM_ADDRESS, true); LOG("Triggered master shutdown"); } diff --git a/dNet/AuthPackets.cpp b/dNet/AuthPackets.cpp index bdce0e30..a46ed9f1 100644 --- a/dNet/AuthPackets.cpp +++ b/dNet/AuthPackets.cpp @@ -19,7 +19,7 @@ #include "dConfig.h" #include "eServerDisconnectIdentifiers.h" #include "eLoginResponse.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "MessageType/Server.h" #include "MessageType/Master.h" #include "eGameMasterLevel.h" @@ -51,9 +51,10 @@ void AuthPackets::HandleHandshake(dServer* server, Packet* packet) { inStream.Read(clientVersion); inStream.IgnoreBytes(4); - ServiceId serviceId; - inStream.Read(serviceId); - if (serviceId != ServiceId::Client) LOG("WARNING: Service ID is not a Client!"); + ServiceType serviceType; + inStream.Read(serviceType); + if (serviceType != ServiceType::CLIENT) LOG("WARNING: Service is not a Client!"); + inStream.IgnoreBytes(2); uint32_t processID; inStream.Read(processID); @@ -64,24 +65,21 @@ void AuthPackets::HandleHandshake(dServer* server, Packet* packet) { inStream.IgnoreBytes(33); - LOG_DEBUG("Client Data [Version: %i, Service: %s, Process: %u, Port: %u, Sysaddr Port: %u]", clientVersion, StringifiedEnum::ToString(serviceId).data(), processID, port, packet->systemAddress.port); + LOG_DEBUG("Client Data [Version: %i, Service: %s, Process: %u, Port: %u, Sysaddr Port: %u]", clientVersion, StringifiedEnum::ToString(serviceType).data(), processID, port, packet->systemAddress.port); SendHandshake(server, packet->systemAddress, server->GetIP(), server->GetPort(), server->GetServerType()); } -void AuthPackets::SendHandshake(dServer* server, const SystemAddress& sysAddr, const std::string& nextServerIP, uint16_t nextServerPort, const ServerType serverType) { +void AuthPackets::SendHandshake(dServer* server, const SystemAddress& sysAddr, const std::string& nextServerIP, uint16_t nextServerPort, const ServiceType serverType) { RakNet::BitStream bitStream; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::SERVER, MessageType::Server::VERSION_CONFIRM); + BitStreamUtils::WriteHeader(bitStream, ServiceType::COMMON, MessageType::Server::VERSION_CONFIRM); - const auto clientNetVersionString = Game::config->GetValue("client_net_version"); + const auto& clientNetVersionString = Game::config->GetValue("client_net_version"); const uint32_t clientNetVersion = GeneralUtils::TryParse(clientNetVersionString).value_or(171022); bitStream.Write(clientNetVersion); bitStream.Write(861228100); - - if (serverType == ServerType::Auth) bitStream.Write(ServiceId::Auth); - else if (serverType == ServerType::World) bitStream.Write(ServiceId::World); - else bitStream.Write(ServiceId::General); + bitStream.Write(static_cast(serverType)); bitStream.Write(219818307120); server->Send(bitStream, sysAddr, false); @@ -234,7 +232,7 @@ void AuthPackets::HandleLoginRequest(dServer* server, Packet* packet) { void AuthPackets::SendLoginResponse(dServer* server, const SystemAddress& sysAddr, eLoginResponse responseCode, const std::string& errorMsg, const std::string& wServerIP, uint16_t wServerPort, std::string username, std::vector& stamps) { stamps.emplace_back(eStamps::PASSPORT_AUTH_IM_LOGIN_START, 1); RakNet::BitStream loginResponse; - BitStreamUtils::WriteHeader(loginResponse, eConnectionType::CLIENT, MessageType::Client::LOGIN_RESPONSE); + BitStreamUtils::WriteHeader(loginResponse, ServiceType::CLIENT, MessageType::Client::LOGIN_RESPONSE); loginResponse.Write(responseCode); @@ -304,7 +302,7 @@ void AuthPackets::SendLoginResponse(dServer* server, const SystemAddress& sysAdd //Inform the master server that we've created a session for this user: if (responseCode == eLoginResponse::SUCCESS) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::SET_SESSION_KEY); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::SET_SESSION_KEY); bitStream.Write(sessionKey); bitStream.Write(LUString(username)); server->SendToMaster(bitStream); diff --git a/dNet/AuthPackets.h b/dNet/AuthPackets.h index ee1e4586..156862eb 100644 --- a/dNet/AuthPackets.h +++ b/dNet/AuthPackets.h @@ -6,8 +6,8 @@ #include "dNetCommon.h" #include "magic_enum.hpp" -enum class ServerType : uint32_t; enum class eLoginResponse : uint8_t; +enum class ServiceType : uint16_t; class dServer; enum class eStamps : uint32_t { @@ -93,7 +93,7 @@ enum class Language : uint32_t { namespace AuthPackets { void HandleHandshake(dServer* server, Packet* packet); - void SendHandshake(dServer* server, const SystemAddress& sysAddr, const std::string& nextServerIP, uint16_t nextServerPort, const ServerType serverType); + void SendHandshake(dServer* server, const SystemAddress& sysAddr, const std::string& nextServerIP, uint16_t nextServerPort, const ServiceType serverType); void HandleLoginRequest(dServer* server, Packet* packet); void SendLoginResponse(dServer* server, const SystemAddress& sysAddr, eLoginResponse responseCode, const std::string& errorMsg, const std::string& wServerIP, uint16_t wServerPort, std::string username, std::vector& stamps); diff --git a/dNet/BitStreamUtils.cpp b/dNet/BitStreamUtils.cpp index 047a1227..91273785 100644 --- a/dNet/BitStreamUtils.cpp +++ b/dNet/BitStreamUtils.cpp @@ -17,8 +17,7 @@ bool LUBitStream::ReadHeader(RakNet::BitStream& bitStream) { if (messageID != ID_USER_PACKET_ENUM) return false; VALIDATE_READ(bitStream.Read(this->connectionType)); VALIDATE_READ(bitStream.Read(this->internalPacketID)); - uint8_t padding; - VALIDATE_READ(bitStream.Read(padding)); + bitStream.IgnoreBytes(1); return true; } diff --git a/dNet/BitStreamUtils.h b/dNet/BitStreamUtils.h index b9fdae42..24d8c4dc 100644 --- a/dNet/BitStreamUtils.h +++ b/dNet/BitStreamUtils.h @@ -4,7 +4,7 @@ #include "GeneralUtils.h" #include "BitStream.h" #include "MessageIdentifiers.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include #include @@ -47,13 +47,13 @@ struct LUWString { }; struct LUBitStream { - eConnectionType connectionType = eConnectionType::UNKNOWN; + ServiceType connectionType = ServiceType::UNKNOWN; uint32_t internalPacketID = 0xFFFFFFFF; LUBitStream() = default; template - LUBitStream(eConnectionType connectionType, T internalPacketID) { + LUBitStream(ServiceType connectionType, T internalPacketID) { this->connectionType = connectionType; this->internalPacketID = static_cast(internalPacketID); } @@ -71,9 +71,9 @@ struct LUBitStream { namespace BitStreamUtils { template - void WriteHeader(RakNet::BitStream& bitStream, eConnectionType connectionType, T internalPacketID) { + void WriteHeader(RakNet::BitStream& bitStream, ServiceType connectionType, T internalPacketID) { bitStream.Write(ID_USER_PACKET_ENUM); - bitStream.Write(connectionType); + bitStream.Write(connectionType); bitStream.Write(static_cast(internalPacketID)); bitStream.Write(0); } diff --git a/dNet/CMakeLists.txt b/dNet/CMakeLists.txt index 67c2ea1f..9b780b84 100644 --- a/dNet/CMakeLists.txt +++ b/dNet/CMakeLists.txt @@ -10,7 +10,7 @@ set(DNET_SOURCES "AuthPackets.cpp" "ZoneInstanceManager.cpp") add_library(dNet STATIC ${DNET_SOURCES}) -target_link_libraries(dNet PRIVATE bcrypt MD5) +target_link_libraries(dNet PRIVATE bcrypt MD5 glm::glm) target_include_directories(dNet PRIVATE "${PROJECT_SOURCE_DIR}/dCommon" "${PROJECT_SOURCE_DIR}/dCommon/dEnums" diff --git a/dNet/ChatPackets.cpp b/dNet/ChatPackets.cpp index 470374dc..86622ad1 100644 --- a/dNet/ChatPackets.cpp +++ b/dNet/ChatPackets.cpp @@ -9,11 +9,11 @@ #include "Game.h" #include "BitStreamUtils.h" #include "dServer.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "MessageType/Chat.h" void ShowAllRequest::Serialize(RakNet::BitStream& bitStream) { - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::SHOW_ALL); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::SHOW_ALL); bitStream.Write(this->requestor); bitStream.Write(this->displayZoneData); bitStream.Write(this->displayIndividualPlayers); @@ -26,7 +26,7 @@ void ShowAllRequest::Deserialize(RakNet::BitStream& inStream) { } void FindPlayerRequest::Serialize(RakNet::BitStream& bitStream) { - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WHO); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WHO); bitStream.Write(this->requestor); bitStream.Write(this->playerName); } @@ -38,7 +38,7 @@ void FindPlayerRequest::Deserialize(RakNet::BitStream& inStream) { void ChatPackets::SendChatMessage(const SystemAddress& sysAddr, char chatChannel, const std::string& senderName, LWOOBJID playerObjectID, bool senderMythran, const std::u16string& message) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE); bitStream.Write(0); bitStream.Write(chatChannel); @@ -60,7 +60,7 @@ void ChatPackets::SendChatMessage(const SystemAddress& sysAddr, char chatChannel void ChatPackets::SendSystemMessage(const SystemAddress& sysAddr, const std::u16string& message, const bool broadcast) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::GENERAL_CHAT_MESSAGE); bitStream.Write(0); bitStream.Write(4); @@ -92,7 +92,7 @@ void ChatPackets::SendMessageFail(const SystemAddress& sysAddr) { //0x01 - "Upgrade to a full LEGO Universe Membership to chat with other players." CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::SEND_CANNED_TEXT); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::SEND_CANNED_TEXT); bitStream.Write(0); //response type, options above ^ //docs say there's a wstring here-- no idea what it's for, or if it's even needed so leaving it as is for now. SEND_PACKET; @@ -139,7 +139,7 @@ void ChatPackets::TeamInviteInitialResponse::Serialize(RakNet::BitStream& bitstr void ChatPackets::SendRoutedMsg(const LUBitStream& msg, const LWOOBJID targetID, const SystemAddress& sysAddr) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::WORLD_ROUTE_PACKET); bitStream.Write(targetID); // Now write the actual packet diff --git a/dNet/ChatPackets.h b/dNet/ChatPackets.h index 58bb9a1d..53d0eced 100644 --- a/dNet/ChatPackets.h +++ b/dNet/ChatPackets.h @@ -34,7 +34,7 @@ namespace ChatPackets { std::string title; std::string message; - Announcement() : LUBitStream(eConnectionType::CHAT, MessageType::Chat::GM_ANNOUNCE) {}; + Announcement() : LUBitStream(ServiceType::CHAT, MessageType::Chat::GM_ANNOUNCE) {}; virtual void Serialize(RakNet::BitStream& bitStream) const override; }; @@ -43,7 +43,7 @@ namespace ChatPackets { uint32_t missionEmailID{}; LWOOBJID earningPlayerID{}; LUWString earnerName{}; - AchievementNotify() : LUBitStream(eConnectionType::CHAT, MessageType::Chat::ACHIEVEMENT_NOTIFY) {} + AchievementNotify() : LUBitStream(ServiceType::CHAT, MessageType::Chat::ACHIEVEMENT_NOTIFY) {} void Serialize(RakNet::BitStream& bitstream) const override; bool Deserialize(RakNet::BitStream& bitstream) override; }; @@ -51,7 +51,7 @@ namespace ChatPackets { struct TeamInviteInitialResponse : public LUBitStream { bool inviteFailedToSend{}; LUWString playerName{}; - TeamInviteInitialResponse() : LUBitStream(eConnectionType::CLIENT, MessageType::Client::TEAM_INVITE_INITIAL_RESPONSE) {} + TeamInviteInitialResponse() : LUBitStream(ServiceType::CLIENT, MessageType::Client::TEAM_INVITE_INITIAL_RESPONSE) {} void Serialize(RakNet::BitStream& bitstream) const override; // No Deserialize needed on our end diff --git a/dNet/MasterPackets.cpp b/dNet/MasterPackets.cpp index e15cab67..36a23f4f 100644 --- a/dNet/MasterPackets.cpp +++ b/dNet/MasterPackets.cpp @@ -2,7 +2,7 @@ #include "BitStream.h" #include "dCommonVars.h" #include "dServer.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "MessageType/Master.h" #include "BitStreamUtils.h" @@ -10,14 +10,14 @@ void MasterPackets::SendPersistentIDRequest(dServer* server, uint64_t requestID) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::REQUEST_PERSISTENT_ID); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::REQUEST_PERSISTENT_ID); bitStream.Write(requestID); server->SendToMaster(bitStream); } void MasterPackets::SendPersistentIDResponse(dServer* server, const SystemAddress& sysAddr, uint64_t requestID, uint32_t objID) { RakNet::BitStream bitStream; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::REQUEST_PERSISTENT_ID_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::REQUEST_PERSISTENT_ID_RESPONSE); bitStream.Write(requestID); bitStream.Write(objID); @@ -27,7 +27,7 @@ void MasterPackets::SendPersistentIDResponse(dServer* server, const SystemAddres void MasterPackets::SendZoneTransferRequest(dServer* server, uint64_t requestID, bool mythranShift, uint32_t zoneID, uint32_t cloneID) { RakNet::BitStream bitStream; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::REQUEST_ZONE_TRANSFER); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::REQUEST_ZONE_TRANSFER); bitStream.Write(requestID); bitStream.Write(mythranShift); @@ -39,7 +39,7 @@ void MasterPackets::SendZoneTransferRequest(dServer* server, uint64_t requestID, void MasterPackets::SendZoneCreatePrivate(dServer* server, uint32_t zoneID, uint32_t cloneID, const std::string& password) { RakNet::BitStream bitStream; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::CREATE_PRIVATE_ZONE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::CREATE_PRIVATE_ZONE); bitStream.Write(zoneID); bitStream.Write(cloneID); @@ -54,7 +54,7 @@ void MasterPackets::SendZoneCreatePrivate(dServer* server, uint32_t zoneID, uint void MasterPackets::SendZoneRequestPrivate(dServer* server, uint64_t requestID, bool mythranShift, const std::string& password) { RakNet::BitStream bitStream; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::REQUEST_PRIVATE_ZONE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::REQUEST_PRIVATE_ZONE); bitStream.Write(requestID); bitStream.Write(mythranShift); @@ -69,7 +69,7 @@ void MasterPackets::SendZoneRequestPrivate(dServer* server, uint64_t requestID, void MasterPackets::SendWorldReady(dServer* server, LWOMAPID zoneId, LWOINSTANCEID instanceId) { RakNet::BitStream bitStream; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::WORLD_READY); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::WORLD_READY); bitStream.Write(zoneId); bitStream.Write(instanceId); @@ -79,7 +79,7 @@ void MasterPackets::SendWorldReady(dServer* server, LWOMAPID zoneId, LWOINSTANCE void MasterPackets::SendZoneTransferResponse(dServer* server, const SystemAddress& sysAddr, uint64_t requestID, bool mythranShift, uint32_t zoneID, uint32_t zoneInstance, uint32_t zoneClone, const std::string& serverIP, uint32_t serverPort) { RakNet::BitStream bitStream; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::REQUEST_ZONE_TRANSFER_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::REQUEST_ZONE_TRANSFER_RESPONSE); bitStream.Write(requestID); bitStream.Write(mythranShift); @@ -111,7 +111,7 @@ void MasterPackets::HandleServerInfo(Packet* packet) { void MasterPackets::SendServerInfo(dServer* server, Packet* packet) { RakNet::BitStream bitStream; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::SERVER_INFO); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::SERVER_INFO); bitStream.Write(server->GetPort()); bitStream.Write(server->GetZoneID()); diff --git a/dNet/PacketUtils.h b/dNet/PacketUtils.h index 3cd44b5f..cf96bfc0 100644 --- a/dNet/PacketUtils.h +++ b/dNet/PacketUtils.h @@ -5,7 +5,7 @@ #include "BitStream.h" #include -enum class eConnectionType : uint16_t; +enum class ServiceType : uint16_t; namespace PacketUtils { void SavePacket(const std::string& filename, const char* data, size_t length); diff --git a/dNet/WorldPackets.cpp b/dNet/WorldPackets.cpp index dfc92f55..1c9898a9 100644 --- a/dNet/WorldPackets.cpp +++ b/dNet/WorldPackets.cpp @@ -7,7 +7,7 @@ #include "LDFFormat.h" #include "dServer.h" #include "ZCompression.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "BitStreamUtils.h" #include @@ -23,7 +23,7 @@ void HTTPMonitorInfo::Serialize(RakNet::BitStream& bitStream) const { void WorldPackets::SendLoadStaticZone(const SystemAddress& sysAddr, float x, float y, float z, uint32_t checksum, LWOZONEID zone) { RakNet::BitStream bitStream; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::LOAD_STATIC_ZONE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::LOAD_STATIC_ZONE); bitStream.Write(zone.GetMapID()); bitStream.Write(zone.GetInstanceID()); @@ -44,28 +44,28 @@ void WorldPackets::SendLoadStaticZone(const SystemAddress& sysAddr, float x, flo void WorldPackets::SendCharacterCreationResponse(const SystemAddress& sysAddr, eCharacterCreationResponse response) { RakNet::BitStream bitStream; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::CHARACTER_CREATE_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::CHARACTER_CREATE_RESPONSE); bitStream.Write(response); SEND_PACKET; } void WorldPackets::SendCharacterRenameResponse(const SystemAddress& sysAddr, eRenameResponse response) { RakNet::BitStream bitStream; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::CHARACTER_RENAME_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::CHARACTER_RENAME_RESPONSE); bitStream.Write(response); SEND_PACKET; } void WorldPackets::SendCharacterDeleteResponse(const SystemAddress& sysAddr, bool response) { RakNet::BitStream bitStream; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::DELETE_CHARACTER_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::DELETE_CHARACTER_RESPONSE); bitStream.Write(response); SEND_PACKET; } void WorldPackets::SendTransferToWorld(const SystemAddress& sysAddr, const std::string& serverIP, uint32_t serverPort, bool mythranShift) { RakNet::BitStream bitStream; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::TRANSFER_TO_WORLD); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::TRANSFER_TO_WORLD); bitStream.Write(LUString(serverIP)); bitStream.Write(serverPort); @@ -76,7 +76,7 @@ void WorldPackets::SendTransferToWorld(const SystemAddress& sysAddr, const std:: void WorldPackets::SendServerState(const SystemAddress& sysAddr) { RakNet::BitStream bitStream; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::SERVER_STATES); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::SERVER_STATES); bitStream.Write(1); //If the server is receiving this request, it probably is ready anyway. SEND_PACKET; } @@ -84,7 +84,7 @@ void WorldPackets::SendServerState(const SystemAddress& sysAddr) { void WorldPackets::SendCreateCharacter(const SystemAddress& sysAddr, int64_t reputation, LWOOBJID player, const std::string& xmlData, const std::u16string& username, eGameMasterLevel gm, const LWOCLONEID cloneID) { using namespace std; RakNet::BitStream bitStream; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::CREATE_CHARACTER); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::CREATE_CHARACTER); RakNet::BitStream data; @@ -133,7 +133,7 @@ void WorldPackets::SendCreateCharacter(const SystemAddress& sysAddr, int64_t rep void WorldPackets::SendChatModerationResponse(const SystemAddress& sysAddr, bool requestAccepted, uint32_t requestID, const std::string& receiver, std::set> unacceptedItems) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::CHAT_MODERATION_STRING); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::CHAT_MODERATION_STRING); bitStream.Write(unacceptedItems.empty()); // Is sentence ok? bitStream.Write(0x16); // Source ID, unknown @@ -157,7 +157,7 @@ void WorldPackets::SendChatModerationResponse(const SystemAddress& sysAddr, bool void WorldPackets::SendGMLevelChange(const SystemAddress& sysAddr, bool success, eGameMasterLevel highestLevel, eGameMasterLevel prevLevel, eGameMasterLevel newLevel) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::MAKE_GM_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::MAKE_GM_RESPONSE); bitStream.Write(success); bitStream.Write(static_cast(highestLevel)); @@ -169,14 +169,14 @@ void WorldPackets::SendGMLevelChange(const SystemAddress& sysAddr, bool success, void WorldPackets::SendHTTPMonitorInfo(const SystemAddress& sysAddr, const HTTPMonitorInfo& info) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::HTTP_MONITOR_INFO_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::HTTP_MONITOR_INFO_RESPONSE); info.Serialize(bitStream); SEND_PACKET; } void WorldPackets::SendDebugOuput(const SystemAddress& sysAddr, const std::string& data) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::DEBUG_OUTPUT); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::DEBUG_OUTPUT); bitStream.Write(data.size()); bitStream.Write(data); SEND_PACKET; diff --git a/dNet/dServer.cpp b/dNet/dServer.cpp index b743e1f4..0a8e0ab9 100644 --- a/dNet/dServer.cpp +++ b/dNet/dServer.cpp @@ -6,7 +6,7 @@ #include "RakNetworkFactory.h" #include "MessageIdentifiers.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "MessageType/Server.h" #include "MessageType/Master.h" @@ -50,7 +50,7 @@ dServer::dServer( Logger* logger, const std::string masterIP, int masterPort, - ServerType serverType, + ServiceType serverType, dConfig* config, Game::signal_t* lastSignal, const std::string& masterPassword, @@ -87,7 +87,7 @@ dServer::dServer( } else { LOG("FAILED TO START SERVER ON IP/PORT: %s:%i", ip.c_str(), port); #ifdef DARKFLAME_PLATFORM_LINUX - if (mServerType == ServerType::Auth) { + if (mServerType == ServiceType::AUTH) { const auto cwd = BinaryPathFinder::GetBinaryDir(); LOG("Try running the following command before launching again:\n sudo setcap 'cap_net_bind_service=+ep' \"%s/AuthServer\"", cwd.string().c_str()); } @@ -98,7 +98,7 @@ dServer::dServer( mLogger->SetLogToConsole(prevLogSetting); //Connect to master if we are not master: - if (serverType != ServerType::Master) { + if (serverType != ServiceType::MASTER) { SetupForMasterConnection(); if (!ConnectToMaster()) { LOG("Failed ConnectToMaster!"); @@ -106,7 +106,7 @@ dServer::dServer( } //Set up Replica if we're a world server: - if (serverType == ServerType::World) { + if (serverType == ServiceType::WORLD) { mNetIDManager = new NetworkIDManager(); mNetIDManager->SetIsNetworkIDAuthority(true); @@ -151,7 +151,7 @@ Packet* dServer::ReceiveFromMaster() { break; } case ID_USER_PACKET_ENUM: { - if (static_cast(packet->data[1]) == eConnectionType::MASTER) { + if (static_cast(packet->data[1]) == ServiceType::MASTER) { switch (static_cast(packet->data[3])) { case MessageType::Master::REQUEST_ZONE_TRANSFER_RESPONSE: { ZoneInstanceManager::Instance()->HandleRequestZoneTransferResponse(packet); @@ -199,7 +199,7 @@ void dServer::SendToMaster(RakNet::BitStream& bitStream) { void dServer::Disconnect(const SystemAddress& sysAddr, eServerDisconnectIdentifiers disconNotifyID) { RakNet::BitStream bitStream; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::SERVER, MessageType::Server::DISCONNECT_NOTIFY); + BitStreamUtils::WriteHeader(bitStream, ServiceType::COMMON, MessageType::Server::DISCONNECT_NOTIFY); bitStream.Write(disconNotifyID); mPeer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE_ORDERED, 0, sysAddr, false); @@ -257,7 +257,7 @@ void dServer::Shutdown() { mReplicaManager = nullptr; } - if (mServerType != ServerType::Master && mMasterPeer) { + if (mServerType != ServiceType::MASTER && mMasterPeer) { mMasterPeer->Shutdown(1000); RakNetworkFactory::DestroyRakPeerInterface(mMasterPeer); } diff --git a/dNet/dServer.h b/dNet/dServer.h index c25fa1f4..c1b96c1a 100644 --- a/dNet/dServer.h +++ b/dNet/dServer.h @@ -9,21 +9,7 @@ class Logger; class dConfig; enum class eServerDisconnectIdentifiers : uint32_t; - -enum class ServerType : uint32_t { - Master, - Auth, - Chat, - World -}; - -enum class ServiceId : uint32_t{ - General = 0, - Auth = 1, - Chat = 2, - World = 4, - Client = 5, -}; +enum class ServiceType : uint16_t; namespace Game { using signal_t = volatile std::sig_atomic_t; @@ -43,7 +29,7 @@ public: Logger* logger, const std::string masterIP, int masterPort, - ServerType serverType, + ServiceType serverType, dConfig* config, Game::signal_t* shouldShutdown, const std::string& masterPassword, @@ -80,7 +66,7 @@ public: NetworkIDManager* GetNetworkIDManager() { return mNetIDManager; } - const ServerType GetServerType() const { return mServerType; } + ServiceType GetServerType() const { return mServerType; } [[nodiscard]] std::chrono::steady_clock::duration GetUptime() const { @@ -114,7 +100,7 @@ protected: bool mIsInternal; bool mIsOkay; bool mMasterConnectionActive; - ServerType mServerType; + ServiceType mServerType; RakPeerInterface* mMasterPeer = nullptr; SocketDescriptor mMasterSocketDescriptor; diff --git a/dPhysics/CMakeLists.txt b/dPhysics/CMakeLists.txt index 65588b4b..928ff32b 100644 --- a/dPhysics/CMakeLists.txt +++ b/dPhysics/CMakeLists.txt @@ -12,5 +12,5 @@ target_include_directories(dPhysics PUBLIC "." "${PROJECT_SOURCE_DIR}/dCommon/dEnums" ) target_link_libraries(dPhysics - PUBLIC Recast Detour + PUBLIC Recast Detour glm::glm INTERFACE dNavigation dCommon) diff --git a/dPhysics/dpEntity.h b/dPhysics/dpEntity.h index cc47d718..a43da4c3 100644 --- a/dPhysics/dpEntity.h +++ b/dPhysics/dpEntity.h @@ -68,7 +68,7 @@ private: bool m_IsStatic; NiPoint3 m_Position; - NiQuaternion m_Rotation; + NiQuaternion m_Rotation = QuatUtils::IDENTITY; float m_Scale; NiPoint3 m_Velocity; diff --git a/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.cpp b/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.cpp index b64bb7a8..b3938fd4 100644 --- a/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.cpp +++ b/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.cpp @@ -88,7 +88,7 @@ void BossSpiderQueenEnemyServer::WithdrawSpider(Entity* self, const bool withdra GameMessages::SendNotifyClientObject(self->GetObjectID(), u"SetColGroup", 10, 0, 0, "", UNASSIGNED_SYSTEM_ADDRESS); //First rotate for anim - NiQuaternion rot = NiQuaternionConstant::IDENTITY; + NiQuaternion rot = QuatUtils::IDENTITY; controllable->SetStatic(false); @@ -405,7 +405,7 @@ void BossSpiderQueenEnemyServer::OnTimerDone(Entity* self, const std::string tim const auto withdrawn = self->GetBoolean(u"isWithdrawn"); if (!withdrawn) return; - NiQuaternion rot = NiQuaternionConstant::IDENTITY; + NiQuaternion rot = QuatUtils::IDENTITY; //First rotate for anim controllable->SetStatic(false); @@ -600,12 +600,12 @@ void BossSpiderQueenEnemyServer::OnUpdate(Entity* self) { if (!isWithdrawn) return; - if (controllable->GetRotation() == NiQuaternionConstant::IDENTITY) { + if (controllable->GetRotation() == QuatUtils::IDENTITY) { return; } controllable->SetStatic(false); - controllable->SetRotation(NiQuaternionConstant::IDENTITY); + controllable->SetRotation(QuatUtils::IDENTITY); controllable->SetStatic(true); Game::entityManager->SerializeEntity(self); diff --git a/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.h b/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.h index 8f73d99f..b5909000 100644 --- a/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.h +++ b/dScripts/02_server/Enemy/AG/BossSpiderQueenEnemyServer.h @@ -52,7 +52,7 @@ private: ControllablePhysicsComponent* controllable = nullptr; BaseCombatAIComponent* combat = nullptr; - NiQuaternion originRotation; + NiQuaternion originRotation = QuatUtils::IDENTITY; int m_CurrentBossStage = 0; int m_DeathCounter = 0; diff --git a/dScripts/02_server/Enemy/AM/AmDarklingDragon.cpp b/dScripts/02_server/Enemy/AM/AmDarklingDragon.cpp index dd3e0bd4..61d25436 100644 --- a/dScripts/02_server/Enemy/AM/AmDarklingDragon.cpp +++ b/dScripts/02_server/Enemy/AM/AmDarklingDragon.cpp @@ -76,7 +76,7 @@ void AmDarklingDragon::OnHitOrHealResult(Entity* self, Entity* attacker, int32_t self->AddTimer("timeToStunLoop", 1.0f); auto position = self->GetPosition(); - auto forward = self->GetRotation().GetForwardVector(); + auto forward = QuatUtils::Forward(self->GetRotation()); auto backwards = forward * -1; forward.x *= 10; diff --git a/dScripts/02_server/Enemy/FV/FvMaelstromDragon.cpp b/dScripts/02_server/Enemy/FV/FvMaelstromDragon.cpp index 6d80b3ff..b4b038b8 100644 --- a/dScripts/02_server/Enemy/FV/FvMaelstromDragon.cpp +++ b/dScripts/02_server/Enemy/FV/FvMaelstromDragon.cpp @@ -92,7 +92,7 @@ void FvMaelstromDragon::OnHitOrHealResult(Entity* self, Entity* attacker, int32_ self->AddTimer("timeToStunLoop", 1.0f); auto position = self->GetPosition(); - auto forward = self->GetRotation().GetForwardVector(); + auto forward = QuatUtils::Forward(self->GetRotation()); auto backwards = forward * -1; forward.x *= 10; diff --git a/dScripts/02_server/Enemy/General/BaseEnemyApe.cpp b/dScripts/02_server/Enemy/General/BaseEnemyApe.cpp index d0f73bd1..db6754f3 100644 --- a/dScripts/02_server/Enemy/General/BaseEnemyApe.cpp +++ b/dScripts/02_server/Enemy/General/BaseEnemyApe.cpp @@ -66,7 +66,7 @@ void BaseEnemyApe::OnTimerDone(Entity* self, std::string timerName) { const auto position = self->GetPosition(); const auto rotation = self->GetRotation(); - const auto backwardVector = rotation.GetForwardVector() * -1; + const auto backwardVector = QuatUtils::Forward(rotation) * -1; const auto objectPosition = NiPoint3( position.GetX() - (backwardVector.GetX() * 8), position.GetY(), diff --git a/dScripts/02_server/Map/AG/AgCagedBricksServer.cpp b/dScripts/02_server/Map/AG/AgCagedBricksServer.cpp index 4d7e8a64..dd51f5b4 100644 --- a/dScripts/02_server/Map/AG/AgCagedBricksServer.cpp +++ b/dScripts/02_server/Map/AG/AgCagedBricksServer.cpp @@ -24,6 +24,6 @@ void AgCagedBricksServer::OnUse(Entity* self, Entity* user) { auto inv = static_cast(user->GetComponent(eReplicaComponentType::INVENTORY)); if (inv) { - inv->RemoveItem(14553, 1); + inv->RemoveItem(14553, 1, eInventoryType::ALL); } } diff --git a/dScripts/02_server/Map/AG/NpcCowboyServer.cpp b/dScripts/02_server/Map/AG/NpcCowboyServer.cpp index 996a99c2..219110b7 100644 --- a/dScripts/02_server/Map/AG/NpcCowboyServer.cpp +++ b/dScripts/02_server/Map/AG/NpcCowboyServer.cpp @@ -22,7 +22,7 @@ void NpcCowboyServer::OnMissionDialogueOK(Entity* self, Entity* target, int miss inventoryComponent->AddItem(14378, 1, eLootSourceType::NONE); } } else if (missionState == eMissionState::READY_TO_COMPLETE || missionState == eMissionState::COMPLETE_READY_TO_COMPLETE) { - inventoryComponent->RemoveItem(14378, 1); + inventoryComponent->RemoveItem(14378, 1, eInventoryType::ALL); } // Next up hide or show the samples based on the mission state diff --git a/dScripts/02_server/Map/AG/NpcWispServer.cpp b/dScripts/02_server/Map/AG/NpcWispServer.cpp index e087df24..0a6c9fda 100644 --- a/dScripts/02_server/Map/AG/NpcWispServer.cpp +++ b/dScripts/02_server/Map/AG/NpcWispServer.cpp @@ -22,7 +22,7 @@ void NpcWispServer::OnMissionDialogueOK(Entity* self, Entity* target, int missio && maelstromVacuum == nullptr) { inventory->AddItem(maelstromVacuumLot, 1, eLootSourceType::NONE); } else if (missionState == eMissionState::READY_TO_COMPLETE || missionState == eMissionState::COMPLETE_READY_TO_COMPLETE) { - inventory->RemoveItem(maelstromVacuumLot, 1); + inventory->RemoveItem(maelstromVacuumLot, 1, eInventoryType::ALL); } // Next up hide or show the samples based on the mission state diff --git a/dScripts/02_server/Map/AG/RemoveRentalGear.cpp b/dScripts/02_server/Map/AG/RemoveRentalGear.cpp index f9bdf1ce..3b950a58 100644 --- a/dScripts/02_server/Map/AG/RemoveRentalGear.cpp +++ b/dScripts/02_server/Map/AG/RemoveRentalGear.cpp @@ -31,7 +31,7 @@ void RemoveRentalGear::OnMissionDialogueOK(Entity* self, Entity* target, int mis auto* id = inv->FindItemByLot(item); if (id) { inv->UnEquipItem(id); - inv->RemoveItem(id->GetLot(), id->GetCount()); + inv->RemoveItem(id->GetLot(), id->GetCount(), eInventoryType::ALL); } } diff --git a/dScripts/02_server/Map/AM/AmDrawBridge.cpp b/dScripts/02_server/Map/AM/AmDrawBridge.cpp index cd42f196..590024b5 100644 --- a/dScripts/02_server/Map/AM/AmDrawBridge.cpp +++ b/dScripts/02_server/Map/AM/AmDrawBridge.cpp @@ -93,7 +93,7 @@ void AmDrawBridge::MoveBridgeDown(Entity* self, Entity* bridge, bool down) { return; } - auto forwardVect = simplePhysicsComponent->GetRotation().GetForwardVector(); + auto forwardVect = QuatUtils::Forward(simplePhysicsComponent->GetRotation()); auto degrees = down ? 90.0f : -90.0f; diff --git a/dScripts/02_server/Map/AM/AmShieldGenerator.cpp b/dScripts/02_server/Map/AM/AmShieldGenerator.cpp index 7c785c41..da0b65d7 100644 --- a/dScripts/02_server/Map/AM/AmShieldGenerator.cpp +++ b/dScripts/02_server/Map/AM/AmShieldGenerator.cpp @@ -129,7 +129,7 @@ void AmShieldGenerator::EnemyEnteredShield(Entity* self, Entity* intruder) { return; } - auto dir = intruder->GetRotation().GetForwardVector() * -1; + auto dir = QuatUtils::Forward(intruder->GetRotation()) * -1; dir.y += 15; dir.x *= 50; dir.z *= 50; diff --git a/dScripts/02_server/Map/AM/AmShieldGeneratorQuickbuild.cpp b/dScripts/02_server/Map/AM/AmShieldGeneratorQuickbuild.cpp index 32852c22..02932295 100644 --- a/dScripts/02_server/Map/AM/AmShieldGeneratorQuickbuild.cpp +++ b/dScripts/02_server/Map/AM/AmShieldGeneratorQuickbuild.cpp @@ -187,7 +187,7 @@ void AmShieldGeneratorQuickbuild::EnemyEnteredShield(Entity* self, Entity* intru return; } - auto dir = intruder->GetRotation().GetForwardVector() * -1; + auto dir = QuatUtils::Forward(intruder->GetRotation()) * -1; dir.y += 15; dir.x *= 50; dir.z *= 50; diff --git a/dScripts/02_server/Map/AM/AmSkullkinTower.cpp b/dScripts/02_server/Map/AM/AmSkullkinTower.cpp index a6a4b8c8..17ae2ea9 100644 --- a/dScripts/02_server/Map/AM/AmSkullkinTower.cpp +++ b/dScripts/02_server/Map/AM/AmSkullkinTower.cpp @@ -46,23 +46,23 @@ void AmSkullkinTower::SpawnLegs(Entity* self, const std::string& loc) { info.rot = newRot; if (loc == "Right") { - const auto dir = rot.GetForwardVector(); + const auto dir = QuatUtils::Forward(rot); pos.x += dir.x * offset; pos.z += dir.z * offset; info.pos = pos; } else if (loc == "Rear") { - const auto dir = rot.GetRightVector(); + const auto dir = QuatUtils::Right(rot); pos.x += dir.x * offset; pos.z += dir.z * offset; info.pos = pos; } else if (loc == "Left") { - const auto dir = rot.GetForwardVector() * -1; + const auto dir = QuatUtils::Forward(rot) * -1; pos.x += dir.x * offset; pos.z += dir.z * offset; info.pos = pos; } - info.rot = NiQuaternion::LookAt(info.pos, self->GetPosition()); + info.rot = QuatUtils::LookAt(info.pos, self->GetPosition()); auto* entity = Game::entityManager->CreateEntity(info, nullptr, self); diff --git a/dScripts/02_server/Map/FV/ImgBrickConsoleQB.cpp b/dScripts/02_server/Map/FV/ImgBrickConsoleQB.cpp index 88415481..db235f8e 100644 --- a/dScripts/02_server/Map/FV/ImgBrickConsoleQB.cpp +++ b/dScripts/02_server/Map/FV/ImgBrickConsoleQB.cpp @@ -74,13 +74,13 @@ void ImgBrickConsoleQB::OnUse(Entity* self, Entity* user) { if (missionComponent != nullptr && inventoryComponent != nullptr) { if (missionComponent->GetMissionState(1302) == eMissionState::ACTIVE) { - inventoryComponent->RemoveItem(13074, 1); + inventoryComponent->RemoveItem(13074, 1, eInventoryType::ALL); missionComponent->ForceProgressTaskType(1302, 1, 1); } if (missionComponent->GetMissionState(1926) == eMissionState::ACTIVE) { - inventoryComponent->RemoveItem(14472, 1); + inventoryComponent->RemoveItem(14472, 1, eInventoryType::ALL); missionComponent->ForceProgressTaskType(1926, 1, 1); } diff --git a/dScripts/02_server/Map/GF/GfCaptainsCannon.cpp b/dScripts/02_server/Map/GF/GfCaptainsCannon.cpp index 242bfe4f..f0f3099b 100644 --- a/dScripts/02_server/Map/GF/GfCaptainsCannon.cpp +++ b/dScripts/02_server/Map/GF/GfCaptainsCannon.cpp @@ -21,7 +21,7 @@ void GfCaptainsCannon::OnUse(Entity* self, Entity* user) { ); auto position = self->GetPosition(); - auto forward = self->GetRotation().GetForwardVector(); + auto forward = QuatUtils::Forward(self->GetRotation()); position.x += forward.x * -3; position.z += forward.z * -3; diff --git a/dScripts/02_server/Map/GF/MastTeleport.cpp b/dScripts/02_server/Map/GF/MastTeleport.cpp index e181779e..f2adc80f 100644 --- a/dScripts/02_server/Map/GF/MastTeleport.cpp +++ b/dScripts/02_server/Map/GF/MastTeleport.cpp @@ -65,7 +65,7 @@ void MastTeleport::OnTimerDone(Entity* self, std::string timerName) { } else if (timerName == "PlayerAnimDone") { GameMessages::SendStopFXEffect(player, true, "hook"); - auto forward = self->GetRotation().GetForwardVector(); + auto forward = QuatUtils::Forward(self->GetRotation()); const auto degrees = -25.0f; @@ -81,7 +81,7 @@ void MastTeleport::OnTimerDone(Entity* self, std::string timerName) { GameMessages::SendOrientToAngle(playerId, true, rads, player->GetSystemAddress()); - GameMessages::SendTeleport(playerId, position, NiQuaternionConstant::IDENTITY, player->GetSystemAddress()); + GameMessages::SendTeleport(playerId, position, QuatUtils::IDENTITY, player->GetSystemAddress()); GameMessages::SendSetStunned(playerId, eStateChangeType::POP, player->GetSystemAddress(), LWOOBJID_EMPTY, true, true, true, true, true, true, true diff --git a/dScripts/02_server/Map/General/QbSpawner.cpp b/dScripts/02_server/Map/General/QbSpawner.cpp index 6fc93d05..0562fdd8 100644 --- a/dScripts/02_server/Map/General/QbSpawner.cpp +++ b/dScripts/02_server/Map/General/QbSpawner.cpp @@ -45,13 +45,13 @@ void QbSpawner::OnTimerDone(Entity* self, std::string timerName) { if (!gate) return; auto oPos = gate->GetPosition(); - auto oDir = gate->GetRotation().GetForwardVector(); + auto oDir = QuatUtils::Forward(gate->GetRotation()); NiPoint3 newPos( oPos.x + (oDir.x * spawnDist), oPos.y, oPos.z + (oDir.z * spawnDist) ); - auto newRot = NiQuaternion::LookAt(newPos, oPos); + auto newRot = QuatUtils::LookAt(newPos, oPos); for (int i = 0; i < mobTable.size(); i++) { int posOffset = -10; diff --git a/dScripts/02_server/Map/General/TokenConsoleServer.cpp b/dScripts/02_server/Map/General/TokenConsoleServer.cpp index 0a1f679c..68f4130f 100644 --- a/dScripts/02_server/Map/General/TokenConsoleServer.cpp +++ b/dScripts/02_server/Map/General/TokenConsoleServer.cpp @@ -14,7 +14,7 @@ void TokenConsoleServer::OnUse(Entity* self, Entity* user) { //make sure the user has the required amount of infected bricks if (inv && inv->GetLotCount(6194) >= bricksToTake) { //yeet the bricks - inv->RemoveItem(6194, bricksToTake); + inv->RemoveItem(6194, bricksToTake, eInventoryType::ALL); //play sound if (self->HasVar(u"sound1")) { diff --git a/dScripts/02_server/Map/NS/NsTokenConsoleServer.cpp b/dScripts/02_server/Map/NS/NsTokenConsoleServer.cpp index 7d825828..39bda78b 100644 --- a/dScripts/02_server/Map/NS/NsTokenConsoleServer.cpp +++ b/dScripts/02_server/Map/NS/NsTokenConsoleServer.cpp @@ -34,7 +34,7 @@ void NsTokenConsoleServer::OnUse(Entity* self, Entity* user) { return; } - inventoryComponent->RemoveItem(6194, 25); + inventoryComponent->RemoveItem(6194, 25, eInventoryType::ALL); const auto useSound = self->GetVar(u"sound1"); diff --git a/dScripts/02_server/Map/NT/NtCombatChallengeServer.cpp b/dScripts/02_server/Map/NT/NtCombatChallengeServer.cpp index 94ad718f..2b2f16f9 100644 --- a/dScripts/02_server/Map/NT/NtCombatChallengeServer.cpp +++ b/dScripts/02_server/Map/NT/NtCombatChallengeServer.cpp @@ -51,7 +51,7 @@ void NtCombatChallengeServer::OnMessageBoxResponse(Entity* self, Entity* sender, auto* inventoryComponent = sender->GetComponent(); if (inventoryComponent != nullptr) { - inventoryComponent->RemoveItem(3039, 1); + inventoryComponent->RemoveItem(3039, 1, eInventoryType::ALL); } GameMessages::SendPlayNDAudioEmitter(self, sender->GetSystemAddress(), startSound); @@ -108,7 +108,7 @@ void NtCombatChallengeServer::OnChildLoaded(Entity& self, GameMessages::ChildLoa auto* const child = Game::entityManager->GetEntity(childLoaded.childID); if (child) { - child->SetRotation(NiQuaternion::FromEulerAngles(child->GetRotation().GetEulerAngles() += NiPoint3(0, PI, 0))); // rotate 180 degrees + child->SetRotation(QuatUtils::FromEuler(QuatUtils::Euler(child->GetRotation()) += NiPoint3(0, PI, 0))); // rotate 180 degrees } self.SetVar(u"currentTargetID", child->GetObjectID()); diff --git a/dScripts/02_server/Map/NT/NtDukeServer.cpp b/dScripts/02_server/Map/NT/NtDukeServer.cpp index 4ab19445..90defd0c 100644 --- a/dScripts/02_server/Map/NT/NtDukeServer.cpp +++ b/dScripts/02_server/Map/NT/NtDukeServer.cpp @@ -34,7 +34,7 @@ void NtDukeServer::OnMissionDialogueOK(Entity* self, Entity* target, int mission if ((state == eMissionState::AVAILABLE || state == eMissionState::ACTIVE) && lotCount < 1) { inventoryComponent->AddItem(m_SwordLot, 1, eLootSourceType::NONE); } else if (state == eMissionState::READY_TO_COMPLETE) { - inventoryComponent->RemoveItem(m_SwordLot, lotCount); + inventoryComponent->RemoveItem(m_SwordLot, lotCount, eInventoryType::ALL); } } NtBcSubmitServer::OnMissionDialogueOK(self, target, missionID, missionState); diff --git a/dScripts/02_server/Map/NT/NtParadoxPanelServer.cpp b/dScripts/02_server/Map/NT/NtParadoxPanelServer.cpp index 0fe97a26..e64ad2dd 100644 --- a/dScripts/02_server/Map/NT/NtParadoxPanelServer.cpp +++ b/dScripts/02_server/Map/NT/NtParadoxPanelServer.cpp @@ -48,7 +48,7 @@ void NtParadoxPanelServer::OnUse(Entity* self, Entity* user) { RenderComponent::PlayAnimation(user, shockAnim); - const auto dir = self->GetRotation().GetRightVector(); + const auto dir = QuatUtils::Right(self->GetRotation()); GameMessages::SendKnockback(user->GetObjectID(), self->GetObjectID(), self->GetObjectID(), 0, { dir.x * 15, 5, dir.z * 15 }); diff --git a/dScripts/02_server/Map/NT/NtSentinelWalkwayServer.cpp b/dScripts/02_server/Map/NT/NtSentinelWalkwayServer.cpp index cac0c75f..cd9cd9b7 100644 --- a/dScripts/02_server/Map/NT/NtSentinelWalkwayServer.cpp +++ b/dScripts/02_server/Map/NT/NtSentinelWalkwayServer.cpp @@ -18,7 +18,7 @@ void NtSentinelWalkwayServer::OnStartup(Entity* self) { force = 115; } - const auto forward = self->GetRotation().GetRightVector() * -1; + const auto forward = QuatUtils::Right(self->GetRotation()) * -1; phantomPhysicsComponent->SetEffectType(ePhysicsEffectType::PUSH); phantomPhysicsComponent->SetDirectionalMultiplier(force); diff --git a/dScripts/02_server/Map/NT/NtVandaServer.cpp b/dScripts/02_server/Map/NT/NtVandaServer.cpp index 45096387..d10dfb08 100644 --- a/dScripts/02_server/Map/NT/NtVandaServer.cpp +++ b/dScripts/02_server/Map/NT/NtVandaServer.cpp @@ -8,7 +8,7 @@ void NtVandaServer::OnMissionDialogueOK(Entity* self, Entity* target, int missio if (missionID == m_AlienPartMissionID && missionState == eMissionState::READY_TO_COMPLETE) { auto* inventoryComponent = target->GetComponent(); for (const auto& alienPartLot : m_AlienPartLots) { - inventoryComponent->RemoveItem(alienPartLot, 1); + inventoryComponent->RemoveItem(alienPartLot, 1, eInventoryType::ALL); } } NtBcSubmitServer::OnMissionDialogueOK(self, target, missionID, missionState); diff --git a/dScripts/02_server/Map/PR/SpawnGryphonServer.cpp b/dScripts/02_server/Map/PR/SpawnGryphonServer.cpp index cf635fe4..9e22efbf 100644 --- a/dScripts/02_server/Map/PR/SpawnGryphonServer.cpp +++ b/dScripts/02_server/Map/PR/SpawnGryphonServer.cpp @@ -20,7 +20,7 @@ void SpawnGryphonServer::OnUse(Entity* self, Entity* user) { // Little extra for handling the case of the egg being placed the first time if (missionComponent != nullptr && inventoryComponent != nullptr && missionComponent->GetMissionState(1391) == eMissionState::ACTIVE) { - inventoryComponent->RemoveItem(12483, inventoryComponent->GetLotCount(12483)); + inventoryComponent->RemoveItem(12483, inventoryComponent->GetLotCount(12483), eInventoryType::ALL); GameMessages::SendTerminateInteraction(user->GetObjectID(), eTerminateType::FROM_INTERACTION, self->GetObjectID()); return; } diff --git a/dScripts/02_server/Map/njhub/FlameJetServer.cpp b/dScripts/02_server/Map/njhub/FlameJetServer.cpp index 9cb687d8..bf760958 100644 --- a/dScripts/02_server/Map/njhub/FlameJetServer.cpp +++ b/dScripts/02_server/Map/njhub/FlameJetServer.cpp @@ -27,7 +27,7 @@ void FlameJetServer::OnCollisionPhantom(Entity* self, Entity* target) { skillComponent->CalculateBehavior(726, 11723, target->GetObjectID(), true); - auto dir = target->GetRotation().GetForwardVector(); + auto dir = QuatUtils::Forward(target->GetRotation()); dir.y = 25; dir.x = -dir.x * 15; diff --git a/dScripts/02_server/Map/njhub/NjColeNPC.cpp b/dScripts/02_server/Map/njhub/NjColeNPC.cpp index b989f3ee..b2b830aa 100644 --- a/dScripts/02_server/Map/njhub/NjColeNPC.cpp +++ b/dScripts/02_server/Map/njhub/NjColeNPC.cpp @@ -39,7 +39,7 @@ void NjColeNPC::OnMissionDialogueOK(Entity* self, Entity* target, int missionID, } if (inventoryComponent->GetLotCount(14499) > 0) { - inventoryComponent->RemoveItem(14499, 1); + inventoryComponent->RemoveItem(14499, 1, eInventoryType::ALL); } else { return; } diff --git a/dScripts/02_server/Map/njhub/NjScrollChestServer.cpp b/dScripts/02_server/Map/njhub/NjScrollChestServer.cpp index 7156b368..c5ca302e 100644 --- a/dScripts/02_server/Map/njhub/NjScrollChestServer.cpp +++ b/dScripts/02_server/Map/njhub/NjScrollChestServer.cpp @@ -9,7 +9,7 @@ void NjScrollChestServer::OnUse(Entity* self, Entity* user) { if (playerInventory != nullptr && playerInventory->GetLotCount(keyLOT) == 1) { // Check for the key and remove - playerInventory->RemoveItem(keyLOT, 1); + playerInventory->RemoveItem(keyLOT, 1, eInventoryType::ALL); // Reward the player with the item set playerInventory->AddItem(rewardItemLOT, 1, eLootSourceType::NONE); diff --git a/dScripts/NPCAddRemoveItem.cpp b/dScripts/NPCAddRemoveItem.cpp index 13677072..40d0a2a7 100644 --- a/dScripts/NPCAddRemoveItem.cpp +++ b/dScripts/NPCAddRemoveItem.cpp @@ -14,7 +14,7 @@ void NPCAddRemoveItem::OnMissionDialogueOK(Entity* self, Entity* target, int mis if (itemSetting.add && (missionState == eMissionState::AVAILABLE || missionState == eMissionState::COMPLETE_AVAILABLE)) { inventory->AddItem(lot, 1, eLootSourceType::NONE); } else if (itemSetting.remove && (missionState == eMissionState::READY_TO_COMPLETE || missionState == eMissionState::COMPLETE_READY_TO_COMPLETE)) { - inventory->RemoveItem(lot, 1); + inventory->RemoveItem(lot, 1, eInventoryType::ALL); } } } diff --git a/dScripts/ai/AG/AgSpiderBossMessage.cpp b/dScripts/ai/AG/AgSpiderBossMessage.cpp index 4be6ce7f..495225b7 100644 --- a/dScripts/ai/AG/AgSpiderBossMessage.cpp +++ b/dScripts/ai/AG/AgSpiderBossMessage.cpp @@ -36,7 +36,7 @@ void AgSpiderBossMessage::OnCollisionPhantom(Entity* self, Entity* target) { auto box = GetBox(self); // knockback the target - auto forward = self->GetRotation().GetForwardVector(); + auto forward = QuatUtils::Forward(self->GetRotation()); box.boxTarget = target->GetObjectID(); GameMessages::SendPlayFXEffect(target->GetObjectID(), 1378, u"create", "pushBack"); RenderComponent::PlayAnimation(target, "knockback-recovery"); diff --git a/dScripts/ai/GF/GfBanana.cpp b/dScripts/ai/GF/GfBanana.cpp index b06aae6f..93741d24 100644 --- a/dScripts/ai/GF/GfBanana.cpp +++ b/dScripts/ai/GF/GfBanana.cpp @@ -10,8 +10,8 @@ void GfBanana::SpawnBanana(Entity* self) { const auto rotation = self->GetRotation(); position.y += 12; - position.x -= rotation.GetRightVector().x * 5; - position.z -= rotation.GetRightVector().z * 5; + position.x -= QuatUtils::Right(rotation).x * 5; + position.z -= QuatUtils::Right(rotation).z * 5; EntityInfo info{}; diff --git a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h index 39af6e5b..3c9ce83b 100644 --- a/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h +++ b/dScripts/ai/MINIGAME/SG_GF/SERVER/SGCannon.h @@ -22,7 +22,7 @@ struct SGEnemy { struct SGConstants { Vector3 playerStartPosition; - Quaternion playerStartRotation; + Quaternion playerStartRotation = QuatUtils::IDENTITY; LOT cannonLot; uint32_t impactSkillID; LOT projectileLot; diff --git a/dScripts/ai/NS/NsConcertInstrument.cpp b/dScripts/ai/NS/NsConcertInstrument.cpp index de234b2b..d1b25918 100644 --- a/dScripts/ai/NS/NsConcertInstrument.cpp +++ b/dScripts/ai/NS/NsConcertInstrument.cpp @@ -273,7 +273,7 @@ void NsConcertInstrument::RepositionPlayer(Entity* self, Entity* player) { case Keyboard: position.SetX(position.GetX() - 0.45f); position.SetZ(position.GetZ() + 0.75f); - rotation = NiQuaternion::CreateFromAxisAngle(position, -0.8f); // Slight rotation to make the animation sensible + rotation = QuatUtils::AxisAngle(position, -0.8f); // Slight rotation to make the animation sensible break; case Drum: position.SetZ(position.GetZ() - 0.5f); diff --git a/dScripts/ai/PROPERTY/AG/AgPropGuard.cpp b/dScripts/ai/PROPERTY/AG/AgPropGuard.cpp index e8e94b53..4e77cb55 100644 --- a/dScripts/ai/PROPERTY/AG/AgPropGuard.cpp +++ b/dScripts/ai/PROPERTY/AG/AgPropGuard.cpp @@ -24,7 +24,7 @@ void AgPropGuard::OnMissionDialogueOK(Entity* self, Entity* target, int missionI if (id) { inventoryComponent->UnEquipItem(id); - inventoryComponent->RemoveItem(id->GetLot(), id->GetCount()); + inventoryComponent->RemoveItem(id->GetLot(), id->GetCount(), eInventoryType::ALL); } } } else if ( diff --git a/dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.cpp b/dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.cpp index 8ad303a6..7506c096 100644 --- a/dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.cpp +++ b/dScripts/zone/LUPs/RobotCity_Intro/WblRobotCitizen.cpp @@ -10,7 +10,7 @@ void WblRobotCitizen::OnStartup(Entity* self) { void WblRobotCitizen::OnUse(Entity* self, Entity* user) { auto movementAIComponent = self->GetComponent(); if (movementAIComponent) movementAIComponent->Pause(); - auto face = NiQuaternion::LookAt(self->GetPosition(), user->GetPosition()); + auto face = QuatUtils::LookAt(self->GetPosition(), user->GetPosition()); self->SetRotation(face); auto timer = RenderComponent::PlayAnimation(self, "wave", 0.4f); self->AddTimer("animation time", timer); diff --git a/dWorldServer/WorldServer.cpp b/dWorldServer/WorldServer.cpp index 4380edd7..cb7fedd5 100644 --- a/dWorldServer/WorldServer.cpp +++ b/dWorldServer/WorldServer.cpp @@ -64,7 +64,7 @@ #include "NiPoint3.h" #include "eServerDisconnectIdentifiers.h" #include "eObjectBits.h" -#include "eConnectionType.h" +#include "ServiceType.h" #include "MessageType/Server.h" #include "MessageType/Chat.h" #include "MessageType/World.h" @@ -235,7 +235,7 @@ int main(int argc, char** argv) { Game::logger, masterIP, masterPort, - ServerType::World, + ServiceType::WORLD, Game::config, &Game::lastSignal, masterPassword, @@ -554,7 +554,7 @@ void HandlePacketChat(Packet* packet) { } if (packet->data[0] == ID_USER_PACKET_ENUM && packet->length >= 4) { - if (static_cast(packet->data[1]) == eConnectionType::CHAT) { + if (static_cast(packet->data[1]) == ServiceType::CHAT) { switch (static_cast(packet->data[3])) { case MessageType::Chat::WORLD_ROUTE_PACKET: { CINSTREAM_SKIP_HEADER; @@ -672,7 +672,7 @@ void HandlePacketChat(Packet* packet) { void HandleMasterPacket(Packet* packet) { if (packet->length < 2) return; - if (static_cast(packet->data[1]) != eConnectionType::MASTER || packet->length < 4) return; + if (static_cast(packet->data[1]) != ServiceType::MASTER || packet->length < 4) return; switch (static_cast(packet->data[3])) { case MessageType::Master::REQUEST_PERSISTENT_ID_RESPONSE: { CINSTREAM_SKIP_HEADER; @@ -739,7 +739,7 @@ void HandleMasterPacket(Packet* packet) { //Notify master: { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::PLAYER_ADDED); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::PLAYER_ADDED); bitStream.Write(Game::server->GetZoneID()); bitStream.Write(g_InstanceID); Game::server->SendToMaster(bitStream); @@ -756,7 +756,7 @@ void HandleMasterPacket(Packet* packet) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::AFFIRM_TRANSFER_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::AFFIRM_TRANSFER_RESPONSE); bitStream.Write(requestID); Game::server->SendToMaster(bitStream); @@ -830,7 +830,7 @@ void HandlePacket(Packet* packet) { { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::UNEXPECTED_DISCONNECT); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::UNEXPECTED_DISCONNECT); bitStream.Write(user->GetLoggedInChar()); Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false); } @@ -842,7 +842,7 @@ void HandlePacket(Packet* packet) { } CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::PLAYER_REMOVED); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::PLAYER_REMOVED); bitStream.Write(Game::server->GetZoneID()); bitStream.Write(g_InstanceID); Game::server->SendToMaster(bitStream); @@ -854,13 +854,13 @@ void HandlePacket(Packet* packet) { LUBitStream luBitStream; luBitStream.ReadHeader(inStream); - if (luBitStream.connectionType == eConnectionType::SERVER) { + if (luBitStream.connectionType == ServiceType::COMMON) { if (static_cast(luBitStream.internalPacketID) == MessageType::Server::VERSION_CONFIRM) { AuthPackets::HandleHandshake(Game::server, packet); } } - if (luBitStream.connectionType != eConnectionType::WORLD) return; + if (luBitStream.connectionType != ServiceType::WORLD) return; switch (static_cast(luBitStream.internalPacketID)) { case MessageType::World::VALIDATION: { @@ -911,7 +911,7 @@ void HandlePacket(Packet* packet) { //Request the session info from Master: CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::REQUEST_SESSION_KEY); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::REQUEST_SESSION_KEY); bitStream.Write(username); Game::server->SendToMaster(bitStream); @@ -1004,7 +1004,7 @@ void HandlePacket(Packet* packet) { // This means we swapped characters and we need to remove the previous player from the container. if (static_cast(lastCharacter) != playerID) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::UNEXPECTED_DISCONNECT); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::UNEXPECTED_DISCONNECT); bitStream.Write(lastCharacter); Game::chatServer->Send(&bitStream, SYSTEM_PRIORITY, RELIABLE, 0, Game::chatSysAddr, false); } @@ -1048,7 +1048,7 @@ void HandlePacket(Packet* packet) { Game::entityManager->ConstructEntity(player, UNASSIGNED_SYSTEM_ADDRESS); if (respawnPoint != NiPoint3Constant::ZERO) { - GameMessages::SendPlayerReachedRespawnCheckpoint(player, respawnPoint, NiQuaternionConstant::IDENTITY); + GameMessages::SendPlayerReachedRespawnCheckpoint(player, respawnPoint, QuatUtils::IDENTITY); } Game::entityManager->ConstructAllEntities(packet->systemAddress); @@ -1157,7 +1157,7 @@ void HandlePacket(Packet* packet) { // Workaround for not having a UGC server to get model LXFML onto the client so it // can generate the physics and nif for the object. CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CLIENT, MessageType::Client::BLUEPRINT_SAVE_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CLIENT, MessageType::Client::BLUEPRINT_SAVE_RESPONSE); bitStream.Write(LWOOBJID_EMPTY); //always zero so that a check on the client passes bitStream.Write(eBlueprintSaveResponseType::EverythingWorked); bitStream.Write(1); @@ -1189,7 +1189,7 @@ void HandlePacket(Packet* packet) { const auto& playerName = character->GetName(); CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, MessageType::Chat::LOGIN_SESSION_NOTIFY); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, MessageType::Chat::LOGIN_SESSION_NOTIFY); bitStream.Write(player->GetObjectID()); bitStream.Write(playerName.size()); for (size_t i = 0; i < playerName.size(); i++) { @@ -1247,7 +1247,7 @@ void HandlePacket(Packet* packet) { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::CHAT, packet->data[14]); + BitStreamUtils::WriteHeader(bitStream, ServiceType::CHAT, packet->data[14]); //We need to insert the player's objectID so the chat server can find who originated this request: LWOOBJID objectID = 0; @@ -1513,6 +1513,6 @@ void FinalizeShutdown() { void SendShutdownMessageToMaster() { CBITSTREAM; - BitStreamUtils::WriteHeader(bitStream, eConnectionType::MASTER, MessageType::Master::SHUTDOWN_RESPONSE); + BitStreamUtils::WriteHeader(bitStream, ServiceType::MASTER, MessageType::Master::SHUTDOWN_RESPONSE); Game::server->SendToMaster(bitStream); } diff --git a/dZoneManager/Spawner.h b/dZoneManager/Spawner.h index 686c7588..f96e1892 100644 --- a/dZoneManager/Spawner.h +++ b/dZoneManager/Spawner.h @@ -13,7 +13,7 @@ struct SpawnerNode { NiPoint3 position = NiPoint3Constant::ZERO; - NiQuaternion rotation = NiQuaternionConstant::IDENTITY; + NiQuaternion rotation = QuatUtils::IDENTITY; uint32_t nodeID = 0; uint32_t nodeMax = 1; std::vector entities; diff --git a/dZoneManager/Zone.h b/dZoneManager/Zone.h index 206ad1f1..20010c2c 100644 --- a/dZoneManager/Zone.h +++ b/dZoneManager/Zone.h @@ -71,7 +71,7 @@ struct RacingPathWaypoint { struct PathWaypoint { NiPoint3 position; - NiQuaternion rotation; // not included in all, but it's more convenient here + NiQuaternion rotation = QuatUtils::IDENTITY; // not included in all, but it's more convenient here MovingPlatformPathWaypoint movingPlatform; CameraPathWaypoint camera; RacingPathWaypoint racing; @@ -237,7 +237,7 @@ private: uint32_t m_CheckSum; uint32_t m_WorldID; //should be equal to the MapID NiPoint3 m_Spawnpoint; - NiQuaternion m_SpawnpointRotation; + NiQuaternion m_SpawnpointRotation = QuatUtils::IDENTITY; uint32_t m_SceneCount; std::string m_ZonePath; //Path to the .luz's folder diff --git a/dZoneManager/dZMCommon.h b/dZoneManager/dZMCommon.h index bee37e5a..5acdc6b7 100644 --- a/dZoneManager/dZMCommon.h +++ b/dZoneManager/dZMCommon.h @@ -11,7 +11,7 @@ struct SceneObject { uint32_t nodeType; uint32_t glomId; NiPoint3 position; - NiQuaternion rotation; + NiQuaternion rotation = QuatUtils::IDENTITY; float scale = 1.0f; //std::string settings; uint32_t value3; diff --git a/tests/dGameTests/GameDependencies.h b/tests/dGameTests/GameDependencies.h index 9f8dbb2b..480d1387 100644 --- a/tests/dGameTests/GameDependencies.h +++ b/tests/dGameTests/GameDependencies.h @@ -30,7 +30,7 @@ class GameDependenciesTest : public ::testing::Test { protected: void SetUpDependencies() { info.pos = NiPoint3Constant::ZERO; - info.rot = NiQuaternionConstant::IDENTITY; + info.rot = QuatUtils::IDENTITY; info.scale = 1.0f; info.spawner = nullptr; info.lot = 999; diff --git a/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp b/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp index 5108cdec..e75dc5c4 100644 --- a/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp +++ b/tests/dGameTests/dGameMessagesTests/GameMessageTests.cpp @@ -57,16 +57,16 @@ TEST_F(GameMessageTests, SendBlueprintLoadItemResponse) { ASSERT_EQ(bitStream->GetNumberOfUnreadBits(), 200); // First read in the packets' header uint8_t rakNetPacketId{}; - uint16_t remoteConnectionType{}; + uint16_t remoteServiceType{}; uint32_t packetId{}; uint8_t always0{}; bitStream->Read(rakNetPacketId); - bitStream->Read(remoteConnectionType); + bitStream->Read(remoteServiceType); bitStream->Read(packetId); bitStream->Read(always0); ASSERT_EQ(rakNetPacketId, 0x53); - ASSERT_EQ(remoteConnectionType, 0x05); + ASSERT_EQ(remoteServiceType, 0x5); ASSERT_EQ(packetId, 0x17); ASSERT_EQ(always0, 0x00); diff --git a/thirdparty/CMakeLists.txt b/thirdparty/CMakeLists.txt index 9bca9738..46f9e45c 100644 --- a/thirdparty/CMakeLists.txt +++ b/thirdparty/CMakeLists.txt @@ -40,13 +40,15 @@ add_subdirectory(magic_enum) # Create our third party library objects add_subdirectory(raknet) +include(FetchContent) + # Download Backtrace if configured if(UNIX AND NOT APPLE) - include(FetchContent) if (${INCLUDE_BACKTRACE} AND ${COMPILE_BACKTRACE}) FetchContent_Declare( backtrace GIT_REPOSITORY https://github.com/ianlancetaylor/libbacktrace.git + GIT_PROGRESS TRUE ) FetchContent_MakeAvailable(backtrace) @@ -64,6 +66,15 @@ if(UNIX AND NOT APPLE) endif() endif() +FetchContent_Declare( + glm + GIT_REPOSITORY https://github.com/g-truc/glm.git + GIT_TAG bf71a834948186f4097caa076cd2663c69a10e1e #refs/tags/1.0.1 + GIT_PROGRESS TRUE +) + +FetchContent_MakeAvailable(glm) + add_subdirectory(MD5) add_subdirectory(mongoose)