From 073b79b4f64e3fd5318b3a85593289691cce52c6 Mon Sep 17 00:00:00 2001 From: collett Date: Sat, 7 Aug 2021 21:30:07 +0900 Subject: [PATCH] SaveDataEventHandler --- src/common/Common.h | 11 ++++++++++- src/common/Network/PacketDef/Ipcs.h | 1 + .../Network/PacketDef/Zone/ClientZoneDef.h | 6 ++++++ .../Network/PacketDef/Zone/ServerZoneDef.h | 8 ++++++++ src/world/Network/GameConnection.cpp | 1 + src/world/Network/GameConnection.h | 2 ++ src/world/Network/Handlers/EventHandlers.cpp | 19 +++++++++++++++++++ src/world/Script/NativeScriptApi.cpp | 4 ++++ src/world/Script/NativeScriptApi.h | 2 ++ src/world/Script/ScriptMgr.cpp | 15 +++++++++++++-- src/world/Script/ScriptMgr.h | 2 ++ 11 files changed, 68 insertions(+), 3 deletions(-) diff --git a/src/common/Common.h b/src/common/Common.h index 30e499a0..fe8636fd 100644 --- a/src/common/Common.h +++ b/src/common/Common.h @@ -1313,7 +1313,16 @@ namespace Sapphire::Common EmptyCoffer = 11, // seems like no param }; - using PlayerStateFlagList = std::vector< PlayerStateFlag >; + struct EventSaveData + { + uint32_t eventId; + uint16_t scene; + uint16_t unknown1; + uint32_t params[11]; + uint64_t unknown2; + uint8_t unknown3[4]; + uint64_t unknown4; + }; } diff --git a/src/common/Network/PacketDef/Ipcs.h b/src/common/Network/PacketDef/Ipcs.h index 2ecb262f..8cfc59ed 100644 --- a/src/common/Network/PacketDef/Ipcs.h +++ b/src/common/Network/PacketDef/Ipcs.h @@ -399,6 +399,7 @@ namespace Sapphire::Network::Packets ReturnEventHandler = 0x0333, // updated 5.58 TradeReturnEventHandler = 0x0179, // updated 5.58 TradeReturnEventHandler2 = 0x02E1, // updated 5.58 + SaveDataEventHandler = 0x03D7, // updated 5.58 LinkshellEventHandler = 0x016B, // updated 4.5 LinkshellEventHandler1 = 0x016C, // updated 4.5 diff --git a/src/common/Network/PacketDef/Zone/ClientZoneDef.h b/src/common/Network/PacketDef/Zone/ClientZoneDef.h index 45840848..ee7364b7 100644 --- a/src/common/Network/PacketDef/Zone/ClientZoneDef.h +++ b/src/common/Network/PacketDef/Zone/ClientZoneDef.h @@ -446,6 +446,12 @@ struct FFXIVIpcHousingEditInterior : uint16_t slot[10]; }; +struct FFXIVIpcSaveDataEventHandler : + FFXIVIpcBasePacket< SaveDataEventHandler > +{ + Common::EventSaveData data; +}; + } #endif //_CORE_NETWORK_PACKETS_ZONE_CLIENT_IPC_H diff --git a/src/common/Network/PacketDef/Zone/ServerZoneDef.h b/src/common/Network/PacketDef/Zone/ServerZoneDef.h index bd1049e2..cb62d9f7 100644 --- a/src/common/Network/PacketDef/Zone/ServerZoneDef.h +++ b/src/common/Network/PacketDef/Zone/ServerZoneDef.h @@ -2238,6 +2238,14 @@ namespace Sapphire::Network::Packets::Server char memberName[32]; uint8_t padding[3]; }; + + struct FFXIVIpcEventYield : FFXIVIpcBasePacket< EventYield > + { + uint32_t eventId; + uint16_t scene; + uint16_t unknown; + uint64_t unknown2; + }; } #endif /*_CORE_NETWORK_PACKETS_SERVER_IPC_H*/ diff --git a/src/world/Network/GameConnection.cpp b/src/world/Network/GameConnection.cpp index 63048ad8..89a3bbbf 100644 --- a/src/world/Network/GameConnection.cpp +++ b/src/world/Network/GameConnection.cpp @@ -106,6 +106,7 @@ Sapphire::Network::GameConnection::GameConnection( Sapphire::Network::HivePtr pH setZoneHandler( ClientZoneIpcType::TradeReturnEventHandler, "TradeReturnEventHandler", &GameConnection::eventHandlerReturn ); setZoneHandler( ClientZoneIpcType::TradeReturnEventHandler2, "TradeReturnEventHandler2", &GameConnection::eventHandlerReturn ); + setZoneHandler( ClientZoneIpcType::SaveDataEventHandler, "SaveDataEventHandler", &GameConnection::saveDataEventHandler ); setZoneHandler( ClientZoneIpcType::ShopEventHandler, "ShopEventHandler", &GameConnection::eventHandlerShop ); diff --git a/src/world/Network/GameConnection.h b/src/world/Network/GameConnection.h index c3e96d06..76013146 100644 --- a/src/world/Network/GameConnection.h +++ b/src/world/Network/GameConnection.h @@ -208,6 +208,8 @@ namespace Sapphire::Network DECLARE_HANDLER( kickPartyMemberHandler ); DECLARE_HANDLER( disbandPartyHandler ); + + DECLARE_HANDLER( saveDataEventHandler ); }; } diff --git a/src/world/Network/Handlers/EventHandlers.cpp b/src/world/Network/Handlers/EventHandlers.cpp index d1643a30..45a9776d 100644 --- a/src/world/Network/Handlers/EventHandlers.cpp +++ b/src/world/Network/Handlers/EventHandlers.cpp @@ -289,5 +289,24 @@ void Sapphire::Network::GameConnection::eventHandlerShop( const Packets::FFXIVAR scriptMgr.onTalk( player, player.getId(), eventId ); } +void Sapphire::Network::GameConnection::saveDataEventHandler( const Packets::FFXIVARR_PACKET_RAW& inPacket, Entity::Player& player ) +{ + auto& scriptMgr = Common::Service< Scripting::ScriptMgr >::ref(); + auto& eventMgr = Common::Service< World::Manager::EventMgr >::ref(); + const auto packet = ZoneChannelPacket< Client::FFXIVIpcSaveDataEventHandler >( inPacket ); + + const auto eventId = packet.data().data.eventId; + + std::string eventName = "onSaveData"; + std::string objName = eventMgr.getEventName( eventId ); + player.sendDebug( "Calling: {0}.{1} - {2} scene: {3}", objName, eventName, eventId, packet.data().data.scene ); + + scriptMgr.onSaveData( player, packet.data().data ); + + auto response = makeZonePacket< FFXIVIpcEventYield >( player.getId() ); + response->data().eventId = eventId; + response->data().scene = packet.data().data.scene; + player.queuePacket( response ); +} diff --git a/src/world/Script/NativeScriptApi.cpp b/src/world/Script/NativeScriptApi.cpp index a4c827c8..bf21522c 100644 --- a/src/world/Script/NativeScriptApi.cpp +++ b/src/world/Script/NativeScriptApi.cpp @@ -146,6 +146,10 @@ namespace Sapphire::ScriptAPI { } + void EventScript::onSaveData( Sapphire::Entity::Player& player, const Common::EventSaveData& data ) + { + } + /////////////////////////////////////////////////////////////////// EventObjectScript::EventObjectScript( uint32_t eobjId ) : diff --git a/src/world/Script/NativeScriptApi.h b/src/world/Script/NativeScriptApi.h index c060d8a9..09fbd7db 100644 --- a/src/world/Script/NativeScriptApi.h +++ b/src/world/Script/NativeScriptApi.h @@ -172,6 +172,8 @@ namespace Sapphire::ScriptAPI uint32_t catalogId ); virtual void onEObjHit( Sapphire::Entity::Player& player, uint64_t actorId, uint32_t actionId ); + + virtual void onSaveData( Sapphire::Entity::Player& player, const Common::EventSaveData& data ); }; /*! diff --git a/src/world/Script/ScriptMgr.cpp b/src/world/Script/ScriptMgr.cpp index 45d1e11d..f3a8a9f6 100644 --- a/src/world/Script/ScriptMgr.cpp +++ b/src/world/Script/ScriptMgr.cpp @@ -566,8 +566,7 @@ Sapphire::Scripting::NativeScriptMgr& Sapphire::Scripting::ScriptMgr::getNativeS return *m_nativeScriptMgr; } -bool -Sapphire::Scripting::ScriptMgr::onDutyComplete( Sapphire::QuestBattlePtr instance, Sapphire::Entity::Player& player ) +bool Sapphire::Scripting::ScriptMgr::onDutyComplete( Sapphire::QuestBattlePtr instance, Sapphire::Entity::Player& player ) { auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::QuestBattleScript >( instance->getDirectorId() ); if( script ) @@ -578,3 +577,15 @@ Sapphire::Scripting::ScriptMgr::onDutyComplete( Sapphire::QuestBattlePtr instanc return false; } + +bool Sapphire::Scripting::ScriptMgr::onSaveData( Sapphire::Entity::Player& player, const Sapphire::Common::EventSaveData& data ) +{ + auto script = m_nativeScriptMgr->getScript< Sapphire::ScriptAPI::EventScript >( data.eventId ); + if( script ) + { + script->onSaveData( player, data ); + return true; + } + + return false; +} \ No newline at end of file diff --git a/src/world/Script/ScriptMgr.h b/src/world/Script/ScriptMgr.h index 8433013c..676ab6ac 100644 --- a/src/world/Script/ScriptMgr.h +++ b/src/world/Script/ScriptMgr.h @@ -118,6 +118,8 @@ namespace Sapphire::Scripting bool onDutyComplete( QuestBattlePtr instance, Entity::Player& player ); + bool onSaveData( Entity::Player& player, const Common::EventSaveData& data ); + bool loadDir( const std::string& dirname, std::set< std::string >& files, const std::string& ext ); NativeScriptMgr& getNativeScriptHandler();