mirror of
https://github.com/SapphireServer/Sapphire.git
synced 2025-04-25 14:07:46 +00:00
Map previously unmapped eobj and enpc
# Conflicts: # src/world/Manager/EventMgr.cpp
This commit is contained in:
parent
6669300124
commit
a84d0f4154
6 changed files with 69 additions and 54 deletions
30
deps/datReader/DatCategories/bg/lgb.h
vendored
30
deps/datReader/DatCategories/bg/lgb.h
vendored
|
@ -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 );
|
||||
|
|
|
@ -202,7 +202,7 @@ struct EObjData :
|
|||
uint8_t unknown1[0xC];
|
||||
};
|
||||
|
||||
class LGB_EOBJ_ENTRY :
|
||||
struct LGB_EOBJ_ENTRY :
|
||||
public LgbEntry
|
||||
{
|
||||
public:
|
||||
|
|
|
@ -137,7 +137,7 @@ public:
|
|||
};
|
||||
|
||||
LGB_BGPARTS_ENTRY( char* buf, uint32_t offset ) :
|
||||
LgbEntry( buf, offset )
|
||||
LgbEntry( buf, offset )
|
||||
{
|
||||
header = *reinterpret_cast<BgPartsData*>( 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<GimmickData*>( 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 );
|
||||
|
|
|
@ -3,9 +3,17 @@
|
|||
#include <Util/Util.h>
|
||||
#include <Service.h>
|
||||
|
||||
#include <Exd/ExdDataGenerated.h>
|
||||
#include <datReader/DatCategories/bg/LgbTypes.h>
|
||||
#include <datReader/DatCategories/bg/lgb.h>
|
||||
|
||||
#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;
|
||||
}
|
||||
|
|
|
@ -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 );
|
||||
}
|
|
@ -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;
|
||||
|
||||
};
|
||||
|
|
Loading…
Add table
Reference in a new issue