diff --git a/apps/openmw-mp/Networking.cpp b/apps/openmw-mp/Networking.cpp index a9f1deb9c..155f1c55a 100644 --- a/apps/openmw-mp/Networking.cpp +++ b/apps/openmw-mp/Networking.cpp @@ -596,6 +596,21 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) break; } + case ID_SCRIPT_MEMBER_SHORT: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_MEMBER_SHORT from %s", + player->Npc()->mName.c_str()); + + myPacket->Read(event); + + LOG_APPEND(Log::LOG_WARN, "- cellRef: %s", + event->cellRef.mRefID.c_str()); + + myPacket->Send(event, true); + + break; + } + case ID_SCRIPT_GLOBAL_SHORT: { LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Received ID_SCRIPT_GLOBAL_SHORT from %s", @@ -603,8 +618,8 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) myPacket->Read(event); - LOG_APPEND(Log::LOG_WARN, "- globalName: %s\n- shortVal: %i", - event->globalName.c_str(), + LOG_APPEND(Log::LOG_WARN, "- varName: %s\n- shortVal: %i", + event->varName.c_str(), event->shortVal); myPacket->Send(event, true); diff --git a/apps/openmw/mwmp/Main.cpp b/apps/openmw/mwmp/Main.cpp index 2d2543094..fd50bf254 100644 --- a/apps/openmw/mwmp/Main.cpp +++ b/apps/openmw/mwmp/Main.cpp @@ -230,7 +230,7 @@ void Main::PressedKey(int key) // should be ignored because of their potential for spam bool Main::isValidPacketScript(std::string script) { - static const int invalidPacketScriptsCount = 16; + static const int invalidPacketScriptsCount = 17; static const std::string invalidPacketScripts[invalidPacketScriptsCount] = { // Spammy shorts "OutsideBanner", @@ -238,11 +238,12 @@ bool Main::isValidPacketScript(std::string script) "dreamer_talkerEnable", "drenSlaveOwners", "ahnassiScript", - "FaluraScript", "hlormarScript", // Spammy floats "Float", "SignRotate", + "FaluraScript", + "jsaddhaScript", // Spammy globals "wraithguardScript", // Spammy globals leading to crashes diff --git a/apps/openmw/mwmp/Networking.cpp b/apps/openmw/mwmp/Networking.cpp index e3d0505de..eab4598df 100644 --- a/apps/openmw/mwmp/Networking.cpp +++ b/apps/openmw/mwmp/Networking.cpp @@ -12,9 +12,11 @@ #include #include +#include +#include + #include #include -#include #include #include @@ -914,14 +916,42 @@ void Networking::ProcessWorldPacket(RakNet::Packet *packet) break; } + case ID_SCRIPT_MEMBER_SHORT: + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_SCRIPT_MEMBER_SHORT"); + LOG_APPEND(Log::LOG_WARN, "- cellRef: %s\n- index: %i\n- shortVal: %i\n", + event->cellRef.mRefID.c_str(), + event->index, + event->shortVal); + + // Mimic the way a Ptr is fetched in InterpreterContext for similar situations + MWWorld::Ptr ptrFound = MWBase::Environment::get().getWorld()->getPtr(event->cellRef.mRefID, false); + + if (ptrFound) + { + LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "Found %s, %i", + ptrFound.getCellRef().getRefId().c_str(), + ptrFound.getCellRef().getRefNum()); + + ptrFound.getRefData().getLocals().mShorts.at(event->index) = event->shortVal; + std::string scriptId = ptrFound.getClass().getScript(ptrFound); + + ptrFound.getRefData().setLocals( + *MWBase::Environment::get().getWorld()->getStore().get().find(scriptId)); + + ptrFound.getRefData().getLocals().mShorts[event->index] = event->shortVal;; + } + + break; + } case ID_SCRIPT_GLOBAL_SHORT: { LOG_MESSAGE_SIMPLE(Log::LOG_WARN, "%s", "Received ID_SCRIPT_GLOBAL_SHORT"); - LOG_APPEND(Log::LOG_WARN, "- globalName: %s\n- shortVal: %i", - event->globalName.c_str(), + LOG_APPEND(Log::LOG_WARN, "- varName: %s\n- shortVal: %i", + event->varName.c_str(), event->shortVal); - MWBase::Environment::get().getWorld()->setGlobalInt(event->globalName, event->shortVal); + MWBase::Environment::get().getWorld()->setGlobalInt(event->varName, event->shortVal); break; } diff --git a/components/CMakeLists.txt b/components/CMakeLists.txt index d61c206e7..5295a6941 100644 --- a/components/CMakeLists.txt +++ b/components/CMakeLists.txt @@ -164,7 +164,8 @@ add_component_dir (openmw-mp Packets/World/PacketContainerAdd Packets/World/PacketContainerRemove Packets/World/PacketDoorActivate Packets/World/PacketVideoPlay - Packets/World/PacketScriptLocalShort Packets/World/PacketScriptLocalFloat Packets/World/PacketScriptGlobalShort) + Packets/World/PacketScriptLocalShort Packets/World/PacketScriptLocalFloat Packets/World/PacketScriptMemberShort + Packets/World/PacketScriptGlobalShort) add_component_dir (fallback fallback validate diff --git a/components/openmw-mp/Base/WorldEvent.hpp b/components/openmw-mp/Base/WorldEvent.hpp index 89c803792..4ba85cc62 100644 --- a/components/openmw-mp/Base/WorldEvent.hpp +++ b/components/openmw-mp/Base/WorldEvent.hpp @@ -38,7 +38,7 @@ namespace mwmp int index; int shortVal; float floatVal; - std::string globalName; + std::string varName; }; } diff --git a/components/openmw-mp/Controllers/WorldPacketController.cpp b/components/openmw-mp/Controllers/WorldPacketController.cpp index 1fe200de1..6f20953f2 100644 --- a/components/openmw-mp/Controllers/WorldPacketController.cpp +++ b/components/openmw-mp/Controllers/WorldPacketController.cpp @@ -17,6 +17,7 @@ #include "../Packets/World/PacketScriptLocalShort.hpp" #include "../Packets/World/PacketScriptLocalFloat.hpp" +#include "../Packets/World/PacketScriptMemberShort.hpp" #include "../Packets/World/PacketScriptGlobalShort.hpp" #include "WorldPacketController.hpp" @@ -46,6 +47,7 @@ mwmp::WorldPacketController::WorldPacketController(RakNet::RakPeerInterface *pee AddPacket(&packets, peer); AddPacket(&packets, peer); + AddPacket(&packets, peer); AddPacket(&packets, peer); } diff --git a/components/openmw-mp/NetworkMessages.hpp b/components/openmw-mp/NetworkMessages.hpp index 1386641b0..eb9e2c0d6 100644 --- a/components/openmw-mp/NetworkMessages.hpp +++ b/components/openmw-mp/NetworkMessages.hpp @@ -48,6 +48,7 @@ enum GameMessages ID_SCRIPT_LOCAL_SHORT, ID_SCRIPT_LOCAL_FLOAT, + ID_SCRIPT_MEMBER_SHORT, ID_SCRIPT_GLOBAL_SHORT }; diff --git a/components/openmw-mp/Packets/World/PacketScriptGlobalShort.cpp b/components/openmw-mp/Packets/World/PacketScriptGlobalShort.cpp index e0b9f4f83..ffdcb2dd1 100644 --- a/components/openmw-mp/Packets/World/PacketScriptGlobalShort.cpp +++ b/components/openmw-mp/Packets/World/PacketScriptGlobalShort.cpp @@ -12,6 +12,6 @@ void PacketScriptGlobalShort::Packet(RakNet::BitStream *bs, WorldEvent *event, b { WorldPacket::Packet(bs, event, send); - RW(event->globalName, send); + RW(event->varName, send); RW(event->shortVal, send); } diff --git a/components/openmw-mp/Packets/World/PacketScriptMemberShort.cpp b/components/openmw-mp/Packets/World/PacketScriptMemberShort.cpp new file mode 100644 index 000000000..b554748f2 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketScriptMemberShort.cpp @@ -0,0 +1,19 @@ +#include +#include "PacketScriptMemberShort.hpp" + +using namespace mwmp; + +PacketScriptMemberShort::PacketScriptMemberShort(RakNet::RakPeerInterface *peer) : WorldPacket(peer) +{ + packetID = ID_SCRIPT_MEMBER_SHORT; +} + +void PacketScriptMemberShort::Packet(RakNet::BitStream *bs, WorldEvent *event, bool send) +{ + WorldPacket::Packet(bs, event, send); + + RW(event->cellRef.mRefID, send); + + RW(event->index, send); + RW(event->shortVal, send); +} diff --git a/components/openmw-mp/Packets/World/PacketScriptMemberShort.hpp b/components/openmw-mp/Packets/World/PacketScriptMemberShort.hpp new file mode 100644 index 000000000..b52728518 --- /dev/null +++ b/components/openmw-mp/Packets/World/PacketScriptMemberShort.hpp @@ -0,0 +1,17 @@ +#ifndef OPENMW_PACKETSCRIPTMEMBERSHORT_HPP +#define OPENMW_PACKETSCRIPTMEMBERSHORT_HPP + +#include + +namespace mwmp +{ + class PacketScriptMemberShort : public WorldPacket + { + public: + PacketScriptMemberShort(RakNet::RakPeerInterface *peer); + + virtual void Packet(RakNet::BitStream *bs, WorldEvent *event, bool send); + }; +} + +#endif //OPENMW_PACKETSCRIPTMEMBERSHORT_HPP