From 895d1eb7b1823d6df144fde73bfd1116692fb6e4 Mon Sep 17 00:00:00 2001 From: Mordred Date: Sun, 30 Jan 2022 22:32:03 +0100 Subject: [PATCH] Fallback to entranceRect if no entrance circle is found in instance --- deps/datReader/DatCategories/bg/LgbTypes.h | 7 ++- deps/datReader/DatCategories/bg/lgb.h | 11 ++++ src/world/Territory/InstanceContent.cpp | 18 ++++++- src/world/Territory/InstanceContent.h | 58 +++++++++++++-------- src/world/Territory/InstanceObjectCache.cpp | 17 ++++-- src/world/Territory/InstanceObjectCache.h | 10 +++- 6 files changed, 93 insertions(+), 28 deletions(-) diff --git a/deps/datReader/DatCategories/bg/LgbTypes.h b/deps/datReader/DatCategories/bg/LgbTypes.h index 8b9d5ad5..31cbe8b4 100644 --- a/deps/datReader/DatCategories/bg/LgbTypes.h +++ b/deps/datReader/DatCategories/bg/LgbTypes.h @@ -137,7 +137,7 @@ struct EObjData : public InstanceObject uint8_t unknown1[0xC]; }; -enum TriggerBoxShape : uint32_t +enum TriggerBoxShape : int32_t { TriggerBoxShapeBox = 0x1, TriggerBoxShapeSphere = 0x2, @@ -156,6 +156,11 @@ struct TriggerBoxInstanceObject uint32_t reserved; }; +struct EventRangeData : public InstanceObject +{ + TriggerBoxInstanceObject triggerBox; +}; + struct ExitRangeData : public InstanceObject { TriggerBoxInstanceObject triggerBoxType; diff --git a/deps/datReader/DatCategories/bg/lgb.h b/deps/datReader/DatCategories/bg/lgb.h index 085325b7..93688c8e 100644 --- a/deps/datReader/DatCategories/bg/lgb.h +++ b/deps/datReader/DatCategories/bg/lgb.h @@ -150,6 +150,17 @@ public: }; }; +struct LGB_EVENT_RANGE_ENTRY : public LgbEntry +{ +public: + EventRangeData data; + + LGB_EVENT_RANGE_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset ) + { + data = *reinterpret_cast< EventRangeData* >( buf + offset ); + }; +}; + struct LGB_GROUP_HEADER { uint32_t id; diff --git a/src/world/Territory/InstanceContent.cpp b/src/world/Territory/InstanceContent.cpp index a0eb9d7b..286afe57 100644 --- a/src/world/Territory/InstanceContent.cpp +++ b/src/world/Territory/InstanceContent.cpp @@ -6,12 +6,15 @@ #include #include #include - +#include +#include +#include #include "Event/Director.h" #include "Event/EventDefs.h" #include "Script/ScriptMgr.h" #include "WorldServer.h" #include "Manager/PlayerMgr.h" +#include "Manager/TerritoryMgr.h" #include "Manager/EventMgr.h" #include "Actor/Player.h" @@ -23,6 +26,8 @@ #include "Event/EventHandler.h" #include "InstanceContent.h" +#include "InstanceObjectCache.h" + using namespace Sapphire::Common; using namespace Sapphire::Network::Packets; @@ -453,11 +458,22 @@ void Sapphire::InstanceContent::onBeforePlayerZoneIn( Sapphire::Entity::Player& // if a player has already spawned once inside this instance, don't move them if they happen to zone in again if( !hasPlayerPreviouslySpawned( player ) ) { + auto& exdData = Common::Service< Data::ExdData >::ref(); + auto& instanceObjectCache = Common::Service< InstanceObjectCache >::ref(); + auto contentInfo = exdData.getRow< Excel::InstanceContent >( m_instanceContentId ); + + auto rect = instanceObjectCache.getEventRange( contentInfo->data().EntranceRect ); + if( m_pEntranceEObj != nullptr ) { player.setRot( PI ); player.setPos( m_pEntranceEObj->getPos() ); } + else if( rect ) + { + player.setRot( PI ); + player.setPos( { rect->header.transform.translation.x, rect->header.transform.translation.y, rect->header.transform.translation.z } ); + } else { player.setRot( PI ); diff --git a/src/world/Territory/InstanceContent.h b/src/world/Territory/InstanceContent.h index 45a4228f..c5b5b4db 100644 --- a/src/world/Territory/InstanceContent.h +++ b/src/world/Territory/InstanceContent.h @@ -20,41 +20,55 @@ namespace Sapphire Terminate }; + /*0x40000001 - INSTANCE_CONTENT_ORDER_SYSTEM_START + 0x40000002 - INSTANCE_CONTENT_ORDER_SYSTEM_CLEAR_NORMAL + 0x40000003 - INSTANCE_CONTENT_ORDER_SYSTEM_RESET_???? ( not really sure about that, seems like reset, arg1 must be 1 ) + 0x40000004 - INSTANCE_CONTENT_ORDER_PVP_READY ( unsure ) + 0x40000005 - INSTANCE_CONTENT_ORDER_SYSTEM_RESET + 0x40000006 - INSTANCE_CONTENT_ORDER_SYSTEM_RESTART + 0x40000007 - INSTANCE_CONTENT_ORDER_SYSTEM_VOTE_ENABLE + 0x40000008 - INSTANCE_CONTENT_ORDER_SYSTEM_VOTE_START + 0x40000009 - INSTANCE_CONTENT_ORDER_SYSTEM_VOTE_RESULT + 0x4000000A - INSTANCE_CONTENT_ORDER_SYSTEM_VOTE_CANCEL + 0x4000000B - INSTANCE_CONTENT_ORDER_SYSTEM_UPDATE_CLEAR_MEMBER + 0x4000000C - INSTANCE_CONTENT_ORDER_SYSTEM_PLAY_SHARED_GROUP + 0x4000000D - INSTANCE_CONTENT_ORDER_SYSTEM_SyncTime? + 0x4000000E - INSTANCE_CONTENT_ORDER_SYSTEM_Unknown - no args - some timer set */ enum DirectorEventId : uint32_t { DEBUG_TimeSync = 0xC0000001, - DutyCommence = 0x80000001, - BattleGroundMusic = 0x80000002, - SetStringendoMode = 0x80000003, - DutyComplete = 0x80000004, - InvalidateTodoList = 0x80000005, - LoadingScreen = 0x80000007, - Forward = 0x80000008, - VoteState = 0x80000009, - VoteStart = 0x8000000A, - VoteResult = 0x8000000B, - VoteFinish = 0x8000000C, - TreasureVoteRefresh = 0x8000000D, - SetSharedGroupId = 0x8000000E, - FirstTimeNotify = 0x8000000F + DutyCommence = 0x40000001, + BattleGroundMusic = 0x40000002, + SetStringendoMode = 0x40000003, + DutyComplete = 0x40000004, + InvalidateTodoList = 0x40000005, + LoadingScreen = 0x40000007, + Forward = 0x40000008, + VoteState = 0x40000009, + VoteStart = 0x4000000A, + VoteResult = 0x4000000B, + VoteFinish = 0x4000000C, + TreasureVoteRefresh = 0x4000000D, + SetSharedGroupId = 0x4000000E, + FirstTimeNotify = 0x4000000F }; enum EventHandlerOrderId : uint32_t { SheetDataReady = 0x80000000, - AbortContent = 0x80000001, //forceFlag - LuaOnStartCutscene = 0x80000002, //returnCode - VoteRequest = 0x80000003, //voteType - VoteReplay = 0x80000004 //voteType, accept + AbortContent = 0x40000001, //forceFlag + LuaOnStartCutscene = 0x40000002, //returnCode + VoteRequest = 0x40000003, //voteType + VoteReplay = 0x40000004 //voteType, accept }; enum DirectorSceneId { - None = 0, - SetupEventArgsOnStart = 1, - SetupEventArgsInProgress = 2, + None = 0, + SetupEventArgsOnStart = 1, + SetupEventArgsInProgress = 2, - DutyFailed = 5 + DutyFailed = 5 }; enum TerminateReason : uint8_t diff --git a/src/world/Territory/InstanceObjectCache.cpp b/src/world/Territory/InstanceObjectCache.cpp index 8d06353b..4e541afc 100644 --- a/src/world/Territory/InstanceObjectCache.cpp +++ b/src/world/Territory/InstanceObjectCache.cpp @@ -83,6 +83,7 @@ Sapphire::InstanceObjectCache::InstanceObjectCache() { for( const auto& pEntry : group.entries ) { + if( pEntry->getType() == LgbEntryType::MapRange ) { auto pMapRange = std::reinterpret_pointer_cast< LGB_MAP_RANGE_ENTRY >( pEntry ); @@ -112,6 +113,11 @@ Sapphire::InstanceObjectCache::InstanceObjectCache() auto pENpc = std::reinterpret_pointer_cast< LGB_ENPC_ENTRY >( pEntry ); m_enpcCache.insert( 0, pENpc ); } + else if( pEntry->getType() == LgbEntryType::EventRange ) + { + auto pEventRange = std::reinterpret_pointer_cast< LGB_EVENT_RANGE_ENTRY >( pEntry ); + m_eventRangeCache.insert( 0, pEventRange ); + } } } } @@ -119,8 +125,8 @@ Sapphire::InstanceObjectCache::InstanceObjectCache() std::cout << "\n"; Logger::debug( - "InstanceObjectCache Cached: MapRange: {} ExitRange: {} PopRange: {}", - m_mapRangeCache.size(), m_exitRangeCache.size(), m_popRangeCache.size() + "InstanceObjectCache Cached: MapRange: {} ExitRange: {} PopRange: {} EventNpc: {} EventRange: {}", + m_mapRangeCache.size(), m_exitRangeCache.size(), m_popRangeCache.size(), m_enpcCache.size(), m_eventRangeCache.size() ); } @@ -153,4 +159,9 @@ Sapphire::InstanceObjectCache::ENpcPtr Sapphire::InstanceObjectCache::getENpc( uint32_t eNpcId ) { return m_enpcCache.get( 0, eNpcId ); -} \ No newline at end of file +} + +Sapphire::InstanceObjectCache::EventRangePtr Sapphire::InstanceObjectCache::getEventRange( uint32_t eventRangeId ) +{ + return m_eventRangeCache.get( 0, eventRangeId ); +} diff --git a/src/world/Territory/InstanceObjectCache.h b/src/world/Territory/InstanceObjectCache.h index ebe802fd..dc3c5f13 100644 --- a/src/world/Territory/InstanceObjectCache.h +++ b/src/world/Territory/InstanceObjectCache.h @@ -9,6 +9,7 @@ struct LGB_EXIT_RANGE_ENTRY; struct LGB_POP_RANGE_ENTRY; struct LGB_EOBJ_ENTRY; struct LGB_ENPC_ENTRY; +struct LGB_EVENT_RANGE_ENTRY; namespace Sapphire @@ -57,7 +58,11 @@ namespace Sapphire size_t size() const { - return m_objectCache.size(); + size_t size = 0; + for( auto& it = m_objectCache.begin(); it != m_objectCache.end(); ++it ) + size += it->second.size(); + + return size; } }; @@ -69,6 +74,7 @@ namespace Sapphire using PopRangePtr = std::shared_ptr< LGB_POP_RANGE_ENTRY >; using EObjPtr = std::shared_ptr< LGB_EOBJ_ENTRY >; using ENpcPtr = std::shared_ptr< LGB_ENPC_ENTRY >; + using EventRangePtr = std::shared_ptr< LGB_EVENT_RANGE_ENTRY >; InstanceObjectCache(); ~InstanceObjectCache() = default; @@ -78,6 +84,7 @@ namespace Sapphire PopRangePtr getPopRange( uint16_t zoneId, uint32_t popRangeId ); EObjPtr getEObj( uint32_t eObjId ); ENpcPtr getENpc( uint32_t eNpcId ); + EventRangePtr getEventRange( uint32_t eventRangeId ); private: ObjectCache< LGB_MAP_RANGE_ENTRY > m_mapRangeCache; @@ -85,6 +92,7 @@ namespace Sapphire ObjectCache< LGB_POP_RANGE_ENTRY > m_popRangeCache; ObjectCache< LGB_EOBJ_ENTRY > m_eobjCache; ObjectCache< LGB_ENPC_ENTRY > m_enpcCache; + ObjectCache< LGB_EVENT_RANGE_ENTRY > m_eventRangeCache; std::shared_ptr< Framework > m_pFramework; };