From a84d0f4154fce4651d9c51a733448c36257c9cde Mon Sep 17 00:00:00 2001 From: Mordred Date: Sat, 26 Feb 2022 19:45:19 +0900 Subject: [PATCH] Map previously unmapped eobj and enpc # Conflicts: # src/world/Manager/EventMgr.cpp --- deps/datReader/DatCategories/bg/lgb.h | 30 ++++++++-------- src/tools/nav_export/lgb.h | 2 +- src/tools/pcb_reader/lgb.h | 18 +++++----- src/world/Manager/EventMgr.cpp | 13 +++++++ src/world/Territory/InstanceObjectCache.cpp | 40 +++++++++++---------- src/world/Territory/InstanceObjectCache.h | 20 +++++------ 6 files changed, 69 insertions(+), 54 deletions(-) diff --git a/deps/datReader/DatCategories/bg/lgb.h b/deps/datReader/DatCategories/bg/lgb.h index 25bd5b6b..085325b7 100644 --- a/deps/datReader/DatCategories/bg/lgb.h +++ b/deps/datReader/DatCategories/bg/lgb.h @@ -34,10 +34,10 @@ public: memset( &header, 0, sizeof( header ) ); }; - LgbEntry( char* buf, uint32_t offset ) + LgbEntry( char* buf, size_t offset ) { m_buf = buf; - m_offset = offset; + m_offset = static_cast< uint32_t >( offset ); header = *reinterpret_cast< InstanceObject* >( buf + offset ); }; @@ -60,11 +60,9 @@ public: std::string modelFileName; std::string collisionFileName; - LGB_BGPARTS_ENTRY() - { - }; + LGB_BGPARTS_ENTRY() = default; - LGB_BGPARTS_ENTRY( char* buf, uint32_t offset ) : LgbEntry( buf, offset ) + LGB_BGPARTS_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset ) { data = *reinterpret_cast< BgPartsData* >( buf + offset ); name = std::string( buf + offset + header.nameOffset ); @@ -80,7 +78,7 @@ public: std::string name; std::string gimmickFileName; - LGB_GIMMICK_ENTRY( char* buf, uint32_t offset ) : LgbEntry( buf, offset ) + LGB_GIMMICK_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset ) { data = *reinterpret_cast< GimmickData* >( buf + offset ); name = std::string( buf + offset + header.nameOffset ); @@ -88,13 +86,13 @@ public: }; }; -class LGB_ENPC_ENTRY : public LgbEntry +struct LGB_ENPC_ENTRY : public LgbEntry { public: ENpcData data; std::string name; - LGB_ENPC_ENTRY( char* buf, uint32_t offset ) : + LGB_ENPC_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset ) { data = *reinterpret_cast< ENpcData* >( buf + offset ); @@ -102,13 +100,13 @@ public: }; }; -class LGB_EOBJ_ENTRY : public LgbEntry +struct LGB_EOBJ_ENTRY : public LgbEntry { public: EObjData data; std::string name; - LGB_EOBJ_ENTRY( char* buf, uint32_t offset ) : LgbEntry( buf, offset ) + LGB_EOBJ_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset ) { data = *reinterpret_cast< EObjData* >( buf + offset ); name = std::string( buf + offset + header.nameOffset ); @@ -121,7 +119,7 @@ public: MapRangeData data; std::string name; - LGB_MAP_RANGE_ENTRY( char* buf, uint32_t offset ) : LgbEntry( buf, offset ) + LGB_MAP_RANGE_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset ) { data = *reinterpret_cast< MapRangeData* >( buf + offset ); name = std::string( buf + offset + header.nameOffset ); @@ -134,7 +132,7 @@ public: ExitRangeData data; std::string name; - LGB_EXIT_RANGE_ENTRY( char* buf, uint32_t offset ) : LgbEntry( buf, offset ) + LGB_EXIT_RANGE_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset ) { data = *reinterpret_cast< ExitRangeData* >( buf + offset ); name = std::string( buf + offset + header.nameOffset ); @@ -146,7 +144,7 @@ struct LGB_POP_RANGE_ENTRY : public LgbEntry public: PopRangeData data; - LGB_POP_RANGE_ENTRY( char* buf, uint32_t offset ) : LgbEntry( buf, offset ) + LGB_POP_RANGE_ENTRY( char* buf, size_t offset ) : LgbEntry( buf, offset ) { data = *reinterpret_cast< PopRangeData* >( buf + offset ); }; @@ -176,7 +174,7 @@ struct LGB_GROUP std::string name; std::vector< std::shared_ptr< LgbEntry > > entries; - LGB_GROUP( char* buf, LGB_FILE* parentStruct, uint32_t offset ) + LGB_GROUP( char* buf, LGB_FILE* parentStruct, size_t offset ) { parent = parentStruct; header = *reinterpret_cast< LGB_GROUP_HEADER* >( buf + offset ); @@ -257,7 +255,7 @@ struct LGB_FILE throw std::runtime_error( "Invalid LGB file!" ); constexpr auto baseOffset = sizeof( header ); - for( auto i = 0; i < header.groupCount; ++i ) + for( size_t i = 0; i < header.groupCount; ++i ) { const auto groupOffset = baseOffset + *reinterpret_cast< int32_t* >( buf + ( baseOffset + i * 4 ) ); const auto group = LGB_GROUP( buf, this, groupOffset ); diff --git a/src/tools/nav_export/lgb.h b/src/tools/nav_export/lgb.h index 937f2f77..ab4df7f3 100644 --- a/src/tools/nav_export/lgb.h +++ b/src/tools/nav_export/lgb.h @@ -202,7 +202,7 @@ struct EObjData : uint8_t unknown1[0xC]; }; -class LGB_EOBJ_ENTRY : +struct LGB_EOBJ_ENTRY : public LgbEntry { public: diff --git a/src/tools/pcb_reader/lgb.h b/src/tools/pcb_reader/lgb.h index d87a2809..bd3be81c 100644 --- a/src/tools/pcb_reader/lgb.h +++ b/src/tools/pcb_reader/lgb.h @@ -137,7 +137,7 @@ public: }; LGB_BGPARTS_ENTRY( char* buf, uint32_t offset ) : - LgbEntry( buf, offset ) + LgbEntry( buf, offset ) { header = *reinterpret_cast( buf + offset ); name = std::string( buf + offset + header.nameOffset ); @@ -162,7 +162,7 @@ public: std::string gimmickFileName; LGB_GIMMICK_ENTRY( char* buf, uint32_t offset ) : - LgbEntry( buf, offset ) + LgbEntry( buf, offset ) { header = *reinterpret_cast( buf + offset ); name = std::string( buf + offset + header.nameOffset ); @@ -178,7 +178,7 @@ struct ENpcData : uint8_t unknown1[0x24]; }; -class LGB_ENPC_ENTRY : +struct LGB_ENPC_ENTRY : public LgbEntry { public: @@ -186,7 +186,7 @@ public: std::string name; LGB_ENPC_ENTRY( char* buf, uint32_t offset ) : - LgbEntry( buf, offset ) + LgbEntry( buf, offset ) { header = *reinterpret_cast< ENpcData* >( buf + offset ); name = std::string( buf + offset + header.nameOffset ); @@ -202,7 +202,7 @@ struct EObjData : uint8_t unknown1[0xC]; }; -class LGB_EOBJ_ENTRY : +struct LGB_EOBJ_ENTRY : public LgbEntry { public: @@ -210,7 +210,7 @@ public: std::string name; LGB_EOBJ_ENTRY( char* buf, uint32_t offset ) : - LgbEntry( buf, offset ) + LgbEntry( buf, offset ) { header = *reinterpret_cast< EObjData* >( buf + offset ); //std::cout << "\t " << header.eobjId << " " << name << " unknown: " << header.unknown << "\n"; @@ -234,7 +234,7 @@ public: std::string name; LGB_MAP_RANGE_ENTRY( char* buf, uint32_t offset ) : - LgbEntry( buf, offset ) + LgbEntry( buf, offset ) { header = *reinterpret_cast< MapRangeData* >( buf + offset ); name = std::string( buf + offset + header.nameOffset ); @@ -254,7 +254,7 @@ struct LGB_COLLISION_BOX_ENTRY : std::string name; LGB_COLLISION_BOX_ENTRY( char* buf, uint32_t offset ) : - LgbEntry( buf, offset ) + LgbEntry( buf, offset ) { header = *reinterpret_cast< LGB_COLLISION_BOX_HEADER* >( buf + offset ); header.type = LgbEntryType::CollisionBox; @@ -366,7 +366,7 @@ struct LGB_FILE { LGB_FILE_HEADER header; std::vector< LGB_GROUP > groups; - + LGB_FILE( char* buf ) { header = *reinterpret_cast< LGB_FILE_HEADER* >( buf ); diff --git a/src/world/Manager/EventMgr.cpp b/src/world/Manager/EventMgr.cpp index bc417c11..cd242f3a 100644 --- a/src/world/Manager/EventMgr.cpp +++ b/src/world/Manager/EventMgr.cpp @@ -3,9 +3,17 @@ #include #include +#include +#include +#include + #include "EventMgr.h" #include "Event/EventHandler.h" +#include "Territory/InstanceObjectCache.h" + +#include "Actor/Player.h" + using namespace Sapphire::Common; std::string Sapphire::World::Manager::EventMgr::getEventName( uint32_t eventId ) @@ -113,10 +121,15 @@ std::string Sapphire::World::Manager::EventMgr::getEventName( uint32_t eventId ) uint32_t Sapphire::World::Manager::EventMgr::mapEventActorToRealActor( uint32_t eventActorId ) { + auto& instanceObjectCache = Common::Service< InstanceObjectCache >::ref(); auto& exdData = Common::Service< Data::ExdDataGenerated >::ref(); auto levelInfo = exdData.get< Sapphire::Data::Level >( eventActorId ); if( levelInfo ) return levelInfo->object; + else if( auto pObj = instanceObjectCache.getEObj( eventActorId ) ) + return pObj->data.eobjId; + else if( auto pNpc = instanceObjectCache.getENpc( eventActorId ) ) + return pNpc->data.enpcId; return 0; } diff --git a/src/world/Territory/InstanceObjectCache.cpp b/src/world/Territory/InstanceObjectCache.cpp index d117df96..66539258 100644 --- a/src/world/Territory/InstanceObjectCache.cpp +++ b/src/world/Territory/InstanceObjectCache.cpp @@ -115,15 +115,19 @@ Sapphire::InstanceObjectCache::InstanceObjectCache() auto pPopRange = std::reinterpret_pointer_cast< LGB_POP_RANGE_ENTRY >( pEntry ); m_popRangeCache.insert( id, pPopRange ); } - else if( pEntry->getType() == LgbEntryType::EventNpc ) + else if( pEntry->getType() == LgbEntryType::SharedGroup6 ) { - auto pEventNpc = std::reinterpret_pointer_cast< LGB_ENPC_ENTRY >( pEntry ); - m_eventNpcCache.insert( id, pEventNpc ); + } else if( pEntry->getType() == LgbEntryType::EventObject ) { - auto pEventObj = std::reinterpret_pointer_cast< LGB_EOBJ_ENTRY >( pEntry ); - m_eventObjCache.insert( id, pEventObj ); + auto pEObj = std::reinterpret_pointer_cast< LGB_EOBJ_ENTRY >( pEntry ); + m_eobjCache.insert( 0, pEObj ); + } + else if( pEntry->getType() == LgbEntryType::EventNpc ) + { + auto pENpc = std::reinterpret_pointer_cast< LGB_ENPC_ENTRY >( pEntry ); + m_enpcCache.insert( 0, pENpc ); } } } @@ -132,50 +136,50 @@ Sapphire::InstanceObjectCache::InstanceObjectCache() std::cout << "\n"; Logger::debug( - "InstanceObjectCache Cached: MapRange: {} ExitRange: {} PopRange: {} ENpc: {} Eobj: {}", - m_mapRangeCache.size(), m_exitRangeCache.size(), m_popRangeCache.size(), m_eventNpcCache.size(), m_eventObjCache.size() + "InstanceObjectCache Cached: MapRange: {} ExitRange: {} PopRange: {}", + m_mapRangeCache.size(), m_exitRangeCache.size(), m_popRangeCache.size() ); } Sapphire::InstanceObjectCache::MapRangePtr - Sapphire::InstanceObjectCache::getMapRange( uint16_t zoneId, uint32_t mapRangeId ) +Sapphire::InstanceObjectCache::getMapRange( uint16_t zoneId, uint32_t mapRangeId ) { return m_mapRangeCache.get( zoneId, mapRangeId ); } Sapphire::InstanceObjectCache::ExitRangePtr - Sapphire::InstanceObjectCache::getExitRange( uint16_t zoneId, uint32_t exitRangeId ) +Sapphire::InstanceObjectCache::getExitRange( uint16_t zoneId, uint32_t exitRangeId ) { return m_exitRangeCache.get( zoneId, exitRangeId ); } Sapphire::InstanceObjectCache::PopRangePtr - Sapphire::InstanceObjectCache::getPopRange( uint16_t zoneId, uint32_t popRangeId ) +Sapphire::InstanceObjectCache::getPopRange( uint16_t zoneId, uint32_t popRangeId ) { return m_popRangeCache.get( zoneId, popRangeId ); } -Sapphire::InstanceObjectCache::EventNpcPtr - Sapphire::InstanceObjectCache::getEventNpc( uint16_t zoneId, uint32_t eventNpcId ) +Sapphire::InstanceObjectCache::EObjPtr +Sapphire::InstanceObjectCache::getEObj( uint32_t eObjId ) { - return m_eventNpcCache.get( zoneId, eventNpcId ); + return m_eobjCache.get( 0, eObjId ); } -Sapphire::InstanceObjectCache::EventObjPtr - Sapphire::InstanceObjectCache::getEventObj( uint16_t zoneId, uint32_t eventObjId ) +Sapphire::InstanceObjectCache::ENpcPtr +Sapphire::InstanceObjectCache::getENpc( uint32_t eNpcId ) { - return m_eventObjCache.get( zoneId, eventObjId ); + return m_enpcCache.get( 0, eNpcId ); } Sapphire::InstanceObjectCache::EventNpcMapPtr Sapphire::InstanceObjectCache::getAllEventNpc( uint16_t zoneId ) { - return m_eventNpcCache.getAll( zoneId ); + return m_enpcCache.getAll( zoneId ); } Sapphire::InstanceObjectCache::EventObjMapPtr Sapphire::InstanceObjectCache::getAllEventObj( uint16_t zoneId ) { - return m_eventObjCache.getAll( zoneId ); + return m_eobjCache.getAll( zoneId ); } \ No newline at end of file diff --git a/src/world/Territory/InstanceObjectCache.h b/src/world/Territory/InstanceObjectCache.h index 7f8bd17c..7df41b79 100644 --- a/src/world/Territory/InstanceObjectCache.h +++ b/src/world/Territory/InstanceObjectCache.h @@ -7,8 +7,8 @@ struct LGB_MAP_RANGE_ENTRY; struct LGB_EXIT_RANGE_ENTRY; struct LGB_POP_RANGE_ENTRY; -struct LGB_ENPC_ENTRY; struct LGB_EOBJ_ENTRY; +struct LGB_ENPC_ENTRY; namespace Sapphire @@ -65,7 +65,7 @@ namespace Sapphire } } - uint32_t size() const + size_t size() const { return m_objectCache.size(); } @@ -77,11 +77,11 @@ namespace Sapphire using MapRangePtr = std::shared_ptr< LGB_MAP_RANGE_ENTRY >; using ExitRangePtr = std::shared_ptr< LGB_EXIT_RANGE_ENTRY >; using PopRangePtr = std::shared_ptr< LGB_POP_RANGE_ENTRY >; - using EventNpcPtr = std::shared_ptr< LGB_ENPC_ENTRY >; - using EventObjPtr = std::shared_ptr< LGB_EOBJ_ENTRY >; + using EObjPtr = std::shared_ptr< LGB_EOBJ_ENTRY >; + using ENpcPtr = std::shared_ptr< LGB_ENPC_ENTRY >; - using EventNpcMapPtr = std::unordered_map< uint32_t, EventNpcPtr >*; - using EventObjMapPtr = std::unordered_map< uint32_t, EventObjPtr >*; + using EventNpcMapPtr = std::unordered_map< uint32_t, ENpcPtr >*; + using EventObjMapPtr = std::unordered_map< uint32_t, EObjPtr >*; InstanceObjectCache(); ~InstanceObjectCache() = default; @@ -89,8 +89,8 @@ namespace Sapphire MapRangePtr getMapRange( uint16_t zoneId, uint32_t mapRangeId ); ExitRangePtr getExitRange( uint16_t zoneId, uint32_t exitRangeId ); PopRangePtr getPopRange( uint16_t zoneId, uint32_t popRangeId ); - EventNpcPtr getEventNpc( uint16_t zoneId, uint32_t eventNpcId ); - EventObjPtr getEventObj( uint16_t zoneId, uint32_t eventObjId ); + EObjPtr getEObj( uint32_t eObjId ); + ENpcPtr getENpc( uint32_t eNpcId ); EventNpcMapPtr getAllEventNpc( uint16_t zoneId ); EventObjMapPtr getAllEventObj( uint16_t zoneId ); @@ -99,8 +99,8 @@ namespace Sapphire ObjectCache< LGB_MAP_RANGE_ENTRY > m_mapRangeCache; ObjectCache< LGB_EXIT_RANGE_ENTRY > m_exitRangeCache; ObjectCache< LGB_POP_RANGE_ENTRY > m_popRangeCache; - ObjectCache< LGB_ENPC_ENTRY > m_eventNpcCache; - ObjectCache< LGB_EOBJ_ENTRY > m_eventObjCache; + ObjectCache< LGB_EOBJ_ENTRY > m_eobjCache; + ObjectCache< LGB_ENPC_ENTRY > m_enpcCache; std::shared_ptr< Framework > m_pFramework; };