From 45ba202ac2195a802f28f872e0984482bdd9a6d0 Mon Sep 17 00:00:00 2001 From: NotAdam Date: Sun, 5 Jan 2020 20:36:52 +1100 Subject: [PATCH] fix InstanceObjectCache crashing if expansion is not installed --- src/world/Territory/InstanceObjectCache.cpp | 28 +++++++++++++++------ src/world/Territory/InstanceObjectCache.h | 5 ++++ 2 files changed, 26 insertions(+), 7 deletions(-) diff --git a/src/world/Territory/InstanceObjectCache.cpp b/src/world/Territory/InstanceObjectCache.cpp index 1d186fc6..92b16aa4 100644 --- a/src/world/Territory/InstanceObjectCache.cpp +++ b/src/world/Territory/InstanceObjectCache.cpp @@ -12,6 +12,8 @@ #include #include +#include + Sapphire::InstanceObjectCache::InstanceObjectCache( std::shared_ptr< Framework > pFramework ) : m_pFramework( pFramework ) { @@ -35,10 +37,6 @@ Sapphire::InstanceObjectCache::InstanceObjectCache( std::shared_ptr< Framework > if( path.empty() ) continue; - // TODO: Horrible workaround... Fails if expansion is not installed - if( path.find( "ex3" ) != std::string::npos ) - continue; - path = std::string( "bg/" ) + path.substr( 0, path.find( "/level/" ) ); // TODO: it does feel like this needs to be streamlined into the datReader instead of being done here... @@ -47,10 +45,21 @@ Sapphire::InstanceObjectCache::InstanceObjectCache( std::shared_ptr< Framework > std::vector< char > bgSection; std::vector< char > planmapSection; - auto test_file = pExd->getGameData()->getFile( bgLgbPath ); - bgSection = test_file->access_data_sections().at( 0 ); + std::unique_ptr< xiv::dat::File > bgFile; + std::unique_ptr< xiv::dat::File > planmap_file; - auto planmap_file = pExd->getGameData()->getFile( planmapLgbPath ); + try + { + bgFile = pExd->getGameData()->getFile( bgLgbPath ); + planmap_file = pExd->getGameData()->getFile( planmapLgbPath ); + } + catch( std::runtime_error& ) + { + // ignore files that aren't found + continue; + } + + bgSection = bgFile->access_data_sections().at( 0 ); planmapSection = planmap_file->access_data_sections().at( 0 ); std::vector< std::string > stringList; @@ -89,6 +98,11 @@ Sapphire::InstanceObjectCache::InstanceObjectCache( std::shared_ptr< Framework > } } std::cout << "\n"; + + Logger::debug( + "InstanceObjectCache Cached: MapRange: {} ExitRange: {} PopRange: {}", + m_mapRangeCache.size(), m_exitRangeCache.size(), m_popRangeCache.size() + ); } diff --git a/src/world/Territory/InstanceObjectCache.h b/src/world/Territory/InstanceObjectCache.h index cab04b55..74171d7f 100644 --- a/src/world/Territory/InstanceObjectCache.h +++ b/src/world/Territory/InstanceObjectCache.h @@ -53,6 +53,11 @@ namespace Sapphire it->second[ entry.header.instanceId ] = pShared; } } + + uint32_t size() const + { + return m_objectCache.size(); + } }; class InstanceObjectCache