From 174b3d224995c3287a7f012720b01497e22aab37 Mon Sep 17 00:00:00 2001 From: Andrei Kortunov Date: Fri, 13 Apr 2018 09:17:05 +0400 Subject: [PATCH 01/13] Reset an inventory filter after reload or a new game start (bug #4392) --- apps/openmw/mwgui/inventorywindow.cpp | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/apps/openmw/mwgui/inventorywindow.cpp b/apps/openmw/mwgui/inventorywindow.cpp index 7bf8ad025..4acf61d93 100644 --- a/apps/openmw/mwgui/inventorywindow.cpp +++ b/apps/openmw/mwgui/inventorywindow.cpp @@ -129,6 +129,12 @@ namespace MWGui mItemView->setModel(mSortModel); + mFilterAll->setStateSelected(true); + mFilterWeapon->setStateSelected(false); + mFilterApparel->setStateSelected(false); + mFilterMagic->setStateSelected(false); + mFilterMisc->setStateSelected(false); + mPreview->updatePtr(mPtr); mPreview->rebuild(); mPreview->update(); From b08d7b4a3b1a7b82f57a37be633a5ac19278a43a Mon Sep 17 00:00:00 2001 From: Capostrophic Date: Thu, 12 Apr 2018 00:39:11 +0300 Subject: [PATCH 02/13] Use centroid interpolation for shader lighting (fixes #4143) --- files/shaders/objects_fragment.glsl | 4 ++-- files/shaders/objects_vertex.glsl | 4 ++-- files/shaders/terrain_fragment.glsl | 4 ++-- files/shaders/terrain_vertex.glsl | 4 ++-- 4 files changed, 8 insertions(+), 8 deletions(-) diff --git a/files/shaders/objects_fragment.glsl b/files/shaders/objects_fragment.glsl index 5a72b44b3..ed1322609 100644 --- a/files/shaders/objects_fragment.glsl +++ b/files/shaders/objects_fragment.glsl @@ -47,9 +47,9 @@ varying float depth; #define PER_PIXEL_LIGHTING (@normalMap || @forcePPL) #if !PER_PIXEL_LIGHTING -varying vec4 lighting; +centroid varying vec4 lighting; #else -varying vec4 passColor; +centroid varying vec4 passColor; #endif varying vec3 passViewPos; varying vec3 passNormal; diff --git a/files/shaders/objects_vertex.glsl b/files/shaders/objects_vertex.glsl index e140cd6ad..4ed02b9c3 100644 --- a/files/shaders/objects_vertex.glsl +++ b/files/shaders/objects_vertex.glsl @@ -38,9 +38,9 @@ varying float depth; #define PER_PIXEL_LIGHTING (@normalMap || @forcePPL) #if !PER_PIXEL_LIGHTING -varying vec4 lighting; +centroid varying vec4 lighting; #else -varying vec4 passColor; +centroid varying vec4 passColor; #endif varying vec3 passViewPos; varying vec3 passNormal; diff --git a/files/shaders/terrain_fragment.glsl b/files/shaders/terrain_fragment.glsl index 134e838c0..ef6d7f226 100644 --- a/files/shaders/terrain_fragment.glsl +++ b/files/shaders/terrain_fragment.glsl @@ -17,9 +17,9 @@ varying float depth; #define PER_PIXEL_LIGHTING (@normalMap || @forcePPL) #if !PER_PIXEL_LIGHTING -varying vec4 lighting; +centroid varying vec4 lighting; #else -varying vec4 passColor; +centroid varying vec4 passColor; #endif varying vec3 passViewPos; varying vec3 passNormal; diff --git a/files/shaders/terrain_vertex.glsl b/files/shaders/terrain_vertex.glsl index e2a180153..9e7c4a162 100644 --- a/files/shaders/terrain_vertex.glsl +++ b/files/shaders/terrain_vertex.glsl @@ -6,9 +6,9 @@ varying float depth; #define PER_PIXEL_LIGHTING (@normalMap || @forcePPL) #if !PER_PIXEL_LIGHTING -varying vec4 lighting; +centroid varying vec4 lighting; #else -varying vec4 passColor; +centroid varying vec4 passColor; #endif varying vec3 passViewPos; varying vec3 passNormal; From 36e0f0471a3afa910884d0acc197d5dcbbd8f70c Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 17 Apr 2018 15:04:18 +0300 Subject: [PATCH 03/13] [Server] Add SetCreatureNameDisplayState script function --- apps/openmw-mp/Script/Functions/Mechanics.cpp | 11 +++++++++-- apps/openmw-mp/Script/Functions/Mechanics.hpp | 13 ++++++++++++- 2 files changed, 21 insertions(+), 3 deletions(-) diff --git a/apps/openmw-mp/Script/Functions/Mechanics.cpp b/apps/openmw-mp/Script/Functions/Mechanics.cpp index 57790932a..4197300c0 100644 --- a/apps/openmw-mp/Script/Functions/Mechanics.cpp +++ b/apps/openmw-mp/Script/Functions/Mechanics.cpp @@ -159,13 +159,20 @@ void MechanicsFunctions::SetWerewolfState(unsigned short pid, bool isWerewolf) n player->isWerewolf = isWerewolf; } -void MechanicsFunctions::SetCreatureRefId(unsigned short pid, const char *refId, bool displayCreatureName) noexcept +void MechanicsFunctions::SetCreatureRefId(unsigned short pid, const char *refId) noexcept { Player *player; GET_PLAYER(pid, player, ); player->creatureRefId = refId; - player->displayCreatureName = displayCreatureName; +} + +void MechanicsFunctions::SetCreatureNameDisplayState(unsigned short pid, bool displayState) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->displayCreatureName = displayState; } void MechanicsFunctions::SendMarkLocation(unsigned short pid) diff --git a/apps/openmw-mp/Script/Functions/Mechanics.hpp b/apps/openmw-mp/Script/Functions/Mechanics.hpp index 31e379401..cd067a0b7 100644 --- a/apps/openmw-mp/Script/Functions/Mechanics.hpp +++ b/apps/openmw-mp/Script/Functions/Mechanics.hpp @@ -27,6 +27,7 @@ {"SetScale", MechanicsFunctions::SetScale},\ {"SetWerewolfState", MechanicsFunctions::SetWerewolfState},\ {"SetCreatureRefId", MechanicsFunctions::SetCreatureRefId},\ + {"SetCreatureNameDisplayState", MechanicsFunctions::SetCreatureNameDisplayState},\ \ {"SendMarkLocation", MechanicsFunctions::SendMarkLocation},\ {"SendSelectedSpell", MechanicsFunctions::SendSelectedSpell},\ @@ -230,7 +231,17 @@ public: * when hovered over by others. * \return void */ - static void SetCreatureRefId(unsigned short pid, const char *refId, bool displayCreatureName) noexcept; + static void SetCreatureRefId(unsigned short pid, const char *refId) noexcept; + + /** + * \brief Set whether a player's name is replaced by that of the creature they are + * disguised as when other players hover over them. + * + * \param pid The player ID. + * \param displayState The creature name display state. + * \return void + */ + static void SetCreatureNameDisplayState(unsigned short pid, bool displayState) noexcept; /** * \brief Send a PlayerMiscellaneous packet with a Mark location to a player. From 50fe54af5d1d629e6e2980c119680e2795246cb3 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 17 Apr 2018 15:23:10 +0300 Subject: [PATCH 04/13] [Client] Update DedicatedPlayer creature if displayCreatureName changes --- apps/openmw/mwmp/DedicatedPlayer.cpp | 3 ++- apps/openmw/mwmp/DedicatedPlayer.hpp | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/apps/openmw/mwmp/DedicatedPlayer.cpp b/apps/openmw/mwmp/DedicatedPlayer.cpp index dc96c71fd..a5a4d4bed 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.cpp +++ b/apps/openmw/mwmp/DedicatedPlayer.cpp @@ -174,7 +174,7 @@ void DedicatedPlayer::setShapeshift() if (reference) isNpc = ptr.getTypeName() == typeid(ESM::NPC).name(); - if (creatureRefId != previousCreatureRefId) + if (creatureRefId != previousCreatureRefId || displayCreatureName != previousDisplayCreatureName) { if (!creatureRefId.empty() && RecordHelper::doesCreatureExist(creatureRefId)) { @@ -229,6 +229,7 @@ void DedicatedPlayer::setShapeshift() } previousCreatureRefId = creatureRefId; + previousDisplayCreatureName = displayCreatureName; } if (ptr.getTypeName() == typeid(ESM::NPC).name()) diff --git a/apps/openmw/mwmp/DedicatedPlayer.hpp b/apps/openmw/mwmp/DedicatedPlayer.hpp index b9ead74e1..783153a00 100644 --- a/apps/openmw/mwmp/DedicatedPlayer.hpp +++ b/apps/openmw/mwmp/DedicatedPlayer.hpp @@ -75,6 +75,7 @@ namespace mwmp std::string previousRace; std::string previousCreatureRefId; + bool previousDisplayCreatureName; std::string creatureRecordId; }; From 2c9d46a60bd8d35f132cb106e5255d590b13640b Mon Sep 17 00:00:00 2001 From: Andreas Sturmlechner Date: Tue, 17 Apr 2018 23:03:56 +0200 Subject: [PATCH 05/13] Fix build with Qt 5.11_beta3 (dropping qt5_use_modules) --- apps/launcher/CMakeLists.txt | 2 +- apps/opencs/CMakeLists.txt | 2 +- apps/wizard/CMakeLists.txt | 2 +- components/CMakeLists.txt | 2 +- extern/osgQt/CMakeLists.txt | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/apps/launcher/CMakeLists.txt b/apps/launcher/CMakeLists.txt index aec8c2533..99e7b4daa 100644 --- a/apps/launcher/CMakeLists.txt +++ b/apps/launcher/CMakeLists.txt @@ -106,7 +106,7 @@ if (DESIRED_QT_VERSION MATCHES 4) target_link_libraries(openmw-launcher ${QT_QTMAIN_LIBRARY}) endif(WIN32) else() - qt5_use_modules(openmw-launcher Widgets Core) + target_link_libraries(openmw-launcher Qt5::Widgets Qt5::Core) endif() if (BUILD_WITH_CODE_COVERAGE) diff --git a/apps/opencs/CMakeLists.txt b/apps/opencs/CMakeLists.txt index b9279bf91..f07b518a9 100644 --- a/apps/opencs/CMakeLists.txt +++ b/apps/opencs/CMakeLists.txt @@ -246,7 +246,7 @@ if (DESIRED_QT_VERSION MATCHES 4) target_link_libraries(openmw-cs ${QT_QTMAIN_LIBRARY}) endif() else() - qt5_use_modules(openmw-cs Widgets Core Network OpenGL) + target_link_libraries(openmw-cs Qt5::Widgets Qt5::Core Qt5::Network Qt5::OpenGL) endif() if (WIN32) diff --git a/apps/wizard/CMakeLists.txt b/apps/wizard/CMakeLists.txt index 5f7338e52..8d97bbcbf 100644 --- a/apps/wizard/CMakeLists.txt +++ b/apps/wizard/CMakeLists.txt @@ -118,7 +118,7 @@ if (DESIRED_QT_VERSION MATCHES 4) target_link_libraries(openmw-wizard ${QT_QTMAIN_LIBRARY}) endif() else() - qt5_use_modules(openmw-wizard Widgets Core) + target_link_libraries(openmw-wizard Qt5::Widgets Qt5::Core) endif() if (OPENMW_USE_UNSHIELD) diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index 8256f1443..ecb844a9b 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -216,7 +216,7 @@ if (USE_QT) ${QT_QTCORE_LIBRARY} ${QT_QTGUI_LIBRARY}) else() - qt5_use_modules(components Widgets Core) + target_link_libraries(components Qt5::Widgets Qt5::Core) endif() endif() diff --git a/extern/osgQt/CMakeLists.txt b/extern/osgQt/CMakeLists.txt index 3bd08a390..78a4e6034 100644 --- a/extern/osgQt/CMakeLists.txt +++ b/extern/osgQt/CMakeLists.txt @@ -12,7 +12,7 @@ if (DESIRED_QT_VERSION MATCHES 4) include(${QT_USE_FILE}) target_link_libraries(${OSGQT_LIBRARY} ${QT_QTCORE_LIBRARY} ${QT_QTOPENGL_LIBRARY}) else() - qt5_use_modules(${OSGQT_LIBRARY} Core OpenGL) + target_link_libraries(${OSGQT_LIBRARY} Qt5::Core Qt5::OpenGL) endif() link_directories(${CMAKE_CURRENT_BINARY_DIR}) From 2bb7a4253e7ff552fe3b72d365f2f9aa1d99f1ae Mon Sep 17 00:00:00 2001 From: David Cernat Date: Tue, 17 Apr 2018 16:36:48 +0300 Subject: [PATCH 06/13] [Server] Forcibly kick players after too many handshake attempts --- apps/openmw-mp/Networking.cpp | 11 +++++++---- apps/openmw-mp/Networking.hpp | 2 +- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index 663256dd7..30c580f53 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -121,8 +121,11 @@ void Networking::processPlayerPacket(RakNet::Packet *packet) LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Attempts so far: %i", player->getHandshakeAttempts()); - if (player->getHandshakeAttempts() > 5) - kickPlayer(player->guid); + if (player->getHandshakeAttempts() > 20) + kickPlayer(player->guid, false); + else if (player->getHandshakeAttempts() > 5) + kickPlayer(player->guid, true); + return; } @@ -499,9 +502,9 @@ int Networking::mainLoop() return exitCode; } -void Networking::kickPlayer(RakNet::RakNetGUID guid) +void Networking::kickPlayer(RakNet::RakNetGUID guid, bool sendNotification) { - peer->CloseConnection(guid, true); + peer->CloseConnection(guid, sendNotification); } void Networking::banAddress(const char *ipAddress) diff --git a/apps/openmw-mp/Networking.hpp b/apps/openmw-mp/Networking.hpp index 913377b0b..74f5090b7 100644 --- a/apps/openmw-mp/Networking.hpp +++ b/apps/openmw-mp/Networking.hpp @@ -22,7 +22,7 @@ namespace mwmp void newPlayer(RakNet::RakNetGUID guid); void disconnectPlayer(RakNet::RakNetGUID guid); - void kickPlayer(RakNet::RakNetGUID guid); + void kickPlayer(RakNet::RakNetGUID guid, bool sendNotification = true); void banAddress(const char *ipAddress); void unbanAddress(const char *ipAddress); From 76e7392a84cc699496b4471dead807b39e7489a1 Mon Sep 17 00:00:00 2001 From: David Cernat Date: Wed, 18 Apr 2018 10:45:39 +0300 Subject: [PATCH 07/13] [Server] Create ShapeshiftFunctions and move relevant functions there --- apps/openmw-mp/CMakeLists.txt | 3 +- apps/openmw-mp/Script/Functions/Mechanics.cpp | 74 ----------- apps/openmw-mp/Script/Functions/Mechanics.hpp | 107 ---------------- .../openmw-mp/Script/Functions/Shapeshift.cpp | 84 ++++++++++++ .../openmw-mp/Script/Functions/Shapeshift.hpp | 120 ++++++++++++++++++ apps/openmw-mp/Script/ScriptFunctions.hpp | 2 + 6 files changed, 208 insertions(+), 182 deletions(-) create mode 100644 apps/openmw-mp/Script/Functions/Shapeshift.cpp create mode 100644 apps/openmw-mp/Script/Functions/Shapeshift.hpp diff --git a/apps/openmw-mp/CMakeLists.txt b/apps/openmw-mp/CMakeLists.txt index 0f5abd684..12691c241 100644 --- a/apps/openmw-mp/CMakeLists.txt +++ b/apps/openmw-mp/CMakeLists.txt @@ -88,7 +88,8 @@ set(SERVER Script/Functions/Chat.cpp Script/Functions/Dialogue.cpp Script/Functions/Factions.cpp Script/Functions/GUI.cpp Script/Functions/Items.cpp Script/Functions/Mechanics.cpp Script/Functions/Positions.cpp Script/Functions/Quests.cpp Script/Functions/Settings.cpp - Script/Functions/Spells.cpp Script/Functions/Stats.cpp Script/Functions/Timer.cpp + Script/Functions/Shapeshift.cpp Script/Functions/Spells.cpp Script/Functions/Stats.cpp + Script/Functions/Timer.cpp Script/API/TimerAPI.cpp Script/API/PublicFnAPI.cpp ${PawnScript_Sources} diff --git a/apps/openmw-mp/Script/Functions/Mechanics.cpp b/apps/openmw-mp/Script/Functions/Mechanics.cpp index 4197300c0..f8d63be84 100644 --- a/apps/openmw-mp/Script/Functions/Mechanics.cpp +++ b/apps/openmw-mp/Script/Functions/Mechanics.cpp @@ -76,38 +76,6 @@ const char *MechanicsFunctions::GetSelectedSpellId(unsigned short pid) noexcept return player->selectedSpellId.c_str(); } -double MechanicsFunctions::GetScale(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player, 0.0f); - - return player->scale; -} - -bool MechanicsFunctions::IsWerewolf(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player, 0); - - return player->isWerewolf; -} - -const char *MechanicsFunctions::GetCreatureRefId(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player, 0); - - return player->creatureRefId.c_str(); -} - -bool MechanicsFunctions::GetCreatureNameDisplayState(unsigned short pid) noexcept -{ - Player *player; - GET_PLAYER(pid, player, 0); - - return player->displayCreatureName; -} - void MechanicsFunctions::SetMarkCell(unsigned short pid, const char *cellDescription) noexcept { Player *player; @@ -143,38 +111,6 @@ void MechanicsFunctions::SetSelectedSpellId(unsigned short pid, const char *spel player->selectedSpellId = spellId; } -void MechanicsFunctions::SetScale(unsigned short pid, double scale) noexcept -{ - Player *player; - GET_PLAYER(pid, player, ); - - player->scale = scale; -} - -void MechanicsFunctions::SetWerewolfState(unsigned short pid, bool isWerewolf) noexcept -{ - Player *player; - GET_PLAYER(pid, player, ); - - player->isWerewolf = isWerewolf; -} - -void MechanicsFunctions::SetCreatureRefId(unsigned short pid, const char *refId) noexcept -{ - Player *player; - GET_PLAYER(pid, player, ); - - player->creatureRefId = refId; -} - -void MechanicsFunctions::SetCreatureNameDisplayState(unsigned short pid, bool displayState) noexcept -{ - Player *player; - GET_PLAYER(pid, player, ); - - player->displayCreatureName = displayState; -} - void MechanicsFunctions::SendMarkLocation(unsigned short pid) { Player *player; @@ -197,16 +133,6 @@ void MechanicsFunctions::SendSelectedSpell(unsigned short pid) mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_MISCELLANEOUS)->Send(false); } -void MechanicsFunctions::SendShapeshift(unsigned short pid) -{ - Player *player; - GET_PLAYER(pid, player, ); - - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SHAPESHIFT)->setPlayer(player); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SHAPESHIFT)->Send(false); - mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SHAPESHIFT)->Send(true); -} - void MechanicsFunctions::Jail(unsigned short pid, int jailDays, bool ignoreJailTeleportation, bool ignoreJailSkillIncreases, const char* jailProgressText, const char* jailEndText) noexcept { diff --git a/apps/openmw-mp/Script/Functions/Mechanics.hpp b/apps/openmw-mp/Script/Functions/Mechanics.hpp index cd067a0b7..737c03750 100644 --- a/apps/openmw-mp/Script/Functions/Mechanics.hpp +++ b/apps/openmw-mp/Script/Functions/Mechanics.hpp @@ -14,24 +14,13 @@ {"GetMarkRotZ", MechanicsFunctions::GetMarkRotZ},\ {"GetSelectedSpellId", MechanicsFunctions::GetSelectedSpellId},\ \ - {"GetScale", MechanicsFunctions::GetScale},\ - {"IsWerewolf", MechanicsFunctions::IsWerewolf},\ - {"GetCreatureRefId", MechanicsFunctions::GetCreatureRefId},\ - {"GetCreatureNameDisplayState", MechanicsFunctions::GetCreatureNameDisplayState},\ - \ {"SetMarkCell", MechanicsFunctions::SetMarkCell},\ {"SetMarkPos", MechanicsFunctions::SetMarkPos},\ {"SetMarkRot", MechanicsFunctions::SetMarkRot},\ {"SetSelectedSpellId", MechanicsFunctions::SetSelectedSpellId},\ \ - {"SetScale", MechanicsFunctions::SetScale},\ - {"SetWerewolfState", MechanicsFunctions::SetWerewolfState},\ - {"SetCreatureRefId", MechanicsFunctions::SetCreatureRefId},\ - {"SetCreatureNameDisplayState", MechanicsFunctions::SetCreatureNameDisplayState},\ - \ {"SendMarkLocation", MechanicsFunctions::SendMarkLocation},\ {"SendSelectedSpell", MechanicsFunctions::SendSelectedSpell},\ - {"SendShapeshift", MechanicsFunctions::SendShapeshift},\ \ {"Jail", MechanicsFunctions::Jail},\ {"Resurrect", MechanicsFunctions::Resurrect} @@ -104,43 +93,6 @@ public: */ static const char *GetSelectedSpellId(unsigned short pid) noexcept; - /** - * \brief Get the scale of a player. - * - * \param pid The player ID. - * \return The scale. - */ - static double GetScale(unsigned short pid) noexcept; - - /** - * \brief Check whether a player is a werewolf. - * - * This is based on the last PlayerShapeshift packet received or sent for that player. - * - * \param pid The player ID. - * \return The werewolf state. - */ - static bool IsWerewolf(unsigned short pid) noexcept; - - /** - * \brief Get the refId of the creature the player is disguised as. - * - * \param pid The player ID. - * \return The creature refId. - */ - static const char *GetCreatureRefId(unsigned short pid) noexcept; - - /** - * \brief Check whether a player's name is replaced by that of the creature they are - * disguised as when other players hover over them. - * - * This is based on the last PlayerShapeshift packet received or sent for that player. - * - * \param pid The player ID. - * \return The creature name display state. - */ - static bool GetCreatureNameDisplayState(unsigned short pid) noexcept; - /** * \brief Set the Mark cell of a player. * @@ -195,54 +147,6 @@ public: */ static void SetSelectedSpellId(unsigned short pid, const char *spellId) noexcept; - /** - * \brief Set the scale of a player. - * - * This changes the scale recorded for that player in the server memory, but - * does not by itself send a packet. - * - * \param pid The player ID. - * \param scale The new scale. - * \return void - */ - static void SetScale(unsigned short pid, double scale) noexcept; - - /** - * \brief Set the werewolf state of a player. - * - * This changes the werewolf state recorded for that player in the server memory, but - * does not by itself send a packet. - * - * \param pid The player ID. - * \param isWerewolf The new werewolf state. - * \return void - */ - static void SetWerewolfState(unsigned short pid, bool isWerewolf) noexcept; - - /** - * \brief Set the refId of the creature a player is disguised as. - * - * This changes the creature refId recorded for that player in the server memory, but - * does not by itself send a packet. - * - * \param pid The player ID. - * \param refId The creature refId. - * \param displaysCreatureName Whether the player's name appears as that of the creature - * when hovered over by others. - * \return void - */ - static void SetCreatureRefId(unsigned short pid, const char *refId) noexcept; - - /** - * \brief Set whether a player's name is replaced by that of the creature they are - * disguised as when other players hover over them. - * - * \param pid The player ID. - * \param displayState The creature name display state. - * \return void - */ - static void SetCreatureNameDisplayState(unsigned short pid, bool displayState) noexcept; - /** * \brief Send a PlayerMiscellaneous packet with a Mark location to a player. * @@ -259,17 +163,6 @@ public: */ static void SendSelectedSpell(unsigned short pid); - /** - * \brief Send a PlayerShapeshift packet about a player. - * - * This sends the packet to all players connected to the server. It is currently used - * only to communicate werewolf states. - * - * \param pid The player ID. - * \return void - */ - static void SendShapeshift(unsigned short pid); - /** * \brief Send a PlayerJail packet about a player. * diff --git a/apps/openmw-mp/Script/Functions/Shapeshift.cpp b/apps/openmw-mp/Script/Functions/Shapeshift.cpp new file mode 100644 index 000000000..2ac33c701 --- /dev/null +++ b/apps/openmw-mp/Script/Functions/Shapeshift.cpp @@ -0,0 +1,84 @@ +#include "Shapeshift.hpp" + +#include +#include + +#include +#include + +#include +using namespace std; + +double ShapeshiftFunctions::GetScale(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0.0f); + + return player->scale; +} + +bool ShapeshiftFunctions::IsWerewolf(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0); + + return player->isWerewolf; +} + +const char *ShapeshiftFunctions::GetCreatureRefId(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0); + + return player->creatureRefId.c_str(); +} + +bool ShapeshiftFunctions::GetCreatureNameDisplayState(unsigned short pid) noexcept +{ + Player *player; + GET_PLAYER(pid, player, 0); + + return player->displayCreatureName; +} + +void ShapeshiftFunctions::SetScale(unsigned short pid, double scale) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->scale = scale; +} + +void ShapeshiftFunctions::SetWerewolfState(unsigned short pid, bool isWerewolf) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->isWerewolf = isWerewolf; +} + +void ShapeshiftFunctions::SetCreatureRefId(unsigned short pid, const char *refId) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->creatureRefId = refId; +} + +void ShapeshiftFunctions::SetCreatureNameDisplayState(unsigned short pid, bool displayState) noexcept +{ + Player *player; + GET_PLAYER(pid, player, ); + + player->displayCreatureName = displayState; +} + +void ShapeshiftFunctions::SendShapeshift(unsigned short pid) +{ + Player *player; + GET_PLAYER(pid, player, ); + + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SHAPESHIFT)->setPlayer(player); + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SHAPESHIFT)->Send(false); + mwmp::Networking::get().getPlayerPacketController()->GetPacket(ID_PLAYER_SHAPESHIFT)->Send(true); +} diff --git a/apps/openmw-mp/Script/Functions/Shapeshift.hpp b/apps/openmw-mp/Script/Functions/Shapeshift.hpp new file mode 100644 index 000000000..4d211185e --- /dev/null +++ b/apps/openmw-mp/Script/Functions/Shapeshift.hpp @@ -0,0 +1,120 @@ +#ifndef OPENMW_SHAPESHIFTAPI_HPP +#define OPENMW_SHAPESHIFTAPI_HPP + +#include "../Types.hpp" + +#define SHAPESHIFTAPI \ + {"GetScale", ShapeshiftFunctions::GetScale},\ + {"IsWerewolf", ShapeshiftFunctions::IsWerewolf},\ + {"GetCreatureRefId", ShapeshiftFunctions::GetCreatureRefId},\ + {"GetCreatureNameDisplayState", ShapeshiftFunctions::GetCreatureNameDisplayState},\ + \ + {"SetScale", ShapeshiftFunctions::SetScale},\ + {"SetWerewolfState", ShapeshiftFunctions::SetWerewolfState},\ + {"SetCreatureRefId", ShapeshiftFunctions::SetCreatureRefId},\ + {"SetCreatureNameDisplayState", ShapeshiftFunctions::SetCreatureNameDisplayState},\ + \ + {"SendShapeshift", ShapeshiftFunctions::SendShapeshift} + +class ShapeshiftFunctions +{ +public: + + /** + * \brief Get the scale of a player. + * + * \param pid The player ID. + * \return The scale. + */ + static double GetScale(unsigned short pid) noexcept; + + /** + * \brief Check whether a player is a werewolf. + * + * This is based on the last PlayerShapeshift packet received or sent for that player. + * + * \param pid The player ID. + * \return The werewolf state. + */ + static bool IsWerewolf(unsigned short pid) noexcept; + + /** + * \brief Get the refId of the creature the player is disguised as. + * + * \param pid The player ID. + * \return The creature refId. + */ + static const char *GetCreatureRefId(unsigned short pid) noexcept; + + /** + * \brief Check whether a player's name is replaced by that of the creature they are + * disguised as when other players hover over them. + * + * This is based on the last PlayerShapeshift packet received or sent for that player. + * + * \param pid The player ID. + * \return The creature name display state. + */ + static bool GetCreatureNameDisplayState(unsigned short pid) noexcept; + + /** + * \brief Set the scale of a player. + * + * This changes the scale recorded for that player in the server memory, but + * does not by itself send a packet. + * + * \param pid The player ID. + * \param scale The new scale. + * \return void + */ + static void SetScale(unsigned short pid, double scale) noexcept; + + /** + * \brief Set the werewolf state of a player. + * + * This changes the werewolf state recorded for that player in the server memory, but + * does not by itself send a packet. + * + * \param pid The player ID. + * \param isWerewolf The new werewolf state. + * \return void + */ + static void SetWerewolfState(unsigned short pid, bool isWerewolf) noexcept; + + /** + * \brief Set the refId of the creature a player is disguised as. + * + * This changes the creature refId recorded for that player in the server memory, but + * does not by itself send a packet. + * + * \param pid The player ID. + * \param refId The creature refId. + * \param displaysCreatureName Whether the player's name appears as that of the creature + * when hovered over by others. + * \return void + */ + static void SetCreatureRefId(unsigned short pid, const char *refId) noexcept; + + /** + * \brief Set whether a player's name is replaced by that of the creature they are + * disguised as when other players hover over them. + * + * \param pid The player ID. + * \param displayState The creature name display state. + * \return void + */ + static void SetCreatureNameDisplayState(unsigned short pid, bool displayState) noexcept; + + /** + * \brief Send a PlayerShapeshift packet about a player. + * + * This sends the packet to all players connected to the server. It is currently used + * only to communicate werewolf states. + * + * \param pid The player ID. + * \return void + */ + static void SendShapeshift(unsigned short pid); +}; + +#endif //OPENMW_SHAPESHIFTAPI_HPP diff --git a/apps/openmw-mp/Script/ScriptFunctions.hpp b/apps/openmw-mp/Script/ScriptFunctions.hpp index caaf3d593..af3ac8b75 100644 --- a/apps/openmw-mp/Script/ScriptFunctions.hpp +++ b/apps/openmw-mp/Script/ScriptFunctions.hpp @@ -17,6 +17,7 @@ #include