1
Fork 0
mirror of https://github.com/SapphireServer/Sapphire.git synced 2025-04-29 07:37:45 +00:00

Merge pull request #257 from GokuWeedLord/actor_rewrite

eobj crash fix, ignore cotire generated files, director branch/seq setters
This commit is contained in:
Mordred 2018-03-01 08:13:17 +01:00 committed by GitHub
commit 20bb4f452d
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
11 changed files with 114 additions and 11 deletions

4
.gitignore vendored
View file

@ -114,3 +114,7 @@ src/common/Version\.cpp
# generated script loader files
src/servers/sapphire_zone/Script/Scripts/*/ScriptLoader.cpp
# cotire generated files/folders
cotire/
*_cotire.cmake

View file

@ -16,6 +16,7 @@ namespace Common {
// 99 is the last spawn id that seems to spawn any actor
const uint8_t MAX_DISPLAYED_ACTORS = 99;
const uint8_t MAX_DISPLAYED_EOBJS = 40;
const int32_t INVALID_GAME_OBJECT_ID = 0xE0000000;

View file

@ -1316,7 +1316,7 @@ struct FFXIVIpcMSQTrackerComplete : FFXIVIpcBasePacket<MSQTrackerComplete>
struct FFXIVIpcObjectSpawn : FFXIVIpcBasePacket<ObjectSpawn>
{
uint8_t count;
uint8_t spawnIndex;
uint8_t objKind;
uint8_t state;
uint8_t unknown3;

View file

@ -100,7 +100,7 @@ void Core::Entity::EventObject::spawn( Core::Entity::PlayerPtr pTarget )
{
g_log.debug( "Spawning EObj: id:" + std::to_string( getId() ) + " name:" + getName() );
ZoneChannelPacket< FFXIVIpcObjectSpawn > eobjStatePacket( getId(), pTarget->getId() );
eobjStatePacket.data().count = pTarget->getNextObjCount();
eobjStatePacket.data().spawnIndex = pTarget->getNextObjSpawnIndexForActorId( getId( ));
eobjStatePacket.data().objKind = getObjKind();
eobjStatePacket.data().state = getState();
eobjStatePacket.data().objId = getObjectId();
@ -115,6 +115,8 @@ void Core::Entity::EventObject::spawn( Core::Entity::PlayerPtr pTarget )
void Core::Entity::EventObject::despawn( Core::Entity::PlayerPtr pTarget )
{
g_log.debug( "despawn eobj: " + std::to_string( getId() ) );
pTarget->freeObjSpawnIndexForActorId( getId( ));
}
const std::string& Core::Entity::EventObject::getName() const

View file

@ -1659,9 +1659,38 @@ void Core::Entity::Player::teleportQuery( uint16_t aetheryteId )
}
}
uint8_t Core::Entity::Player::getNextObjCount()
uint8_t Core::Entity::Player::getNextObjSpawnIndexForActorId( uint32_t actorId )
{
return m_objCount++;
// todo: fix it so the case where there's no ids available doesn't break everything :(
auto nextCount = m_freeObjCounts.front();
m_freeObjCounts.pop();
m_actorIdToObjCountMap[actorId] = nextCount;
return nextCount;
}
void Core::Entity::Player::resetObjSpawnIndex()
{
while( m_freeObjCounts.empty() )
m_freeObjCounts.pop();
for( uint32_t i = 0; i < MAX_DISPLAYED_EOBJS; ++i )
m_freeObjCounts.push( i );
m_actorIdToObjCountMap.clear();
}
void Core::Entity::Player::freeObjSpawnIndexForActorId( uint32_t actorId )
{
auto it = m_actorIdToObjCountMap.find( actorId );
if( it == m_actorIdToObjCountMap.end() )
return;
auto freeCount = m_actorIdToObjCountMap[actorId];
m_freeObjCounts.push( freeCount );
m_actorIdToObjCountMap.erase( actorId );
}
void Core::Entity::Player::setOnEnterEventDone( bool isDone )

View file

@ -562,7 +562,12 @@ public:
void setOnEnterEventDone( bool isDone );
bool isOnEnterEventDone() const;
uint8_t getNextObjCount();
/*! gets the next available obj count */
uint8_t getNextObjSpawnIndexForActorId( uint32_t actorId );
/*! resets the players obj count */
void resetObjSpawnIndex();
/*! frees an obj count to be used by another eobj */
void freeObjSpawnIndexForActorId( uint32_t actorId );
private:
uint32_t m_lastWrite;
@ -679,6 +684,8 @@ private:
// counter used to index objects spawned for the player
uint8_t m_objCount;
std::queue< uint8_t > m_freeObjCounts;
std::map< uint32_t, uint8_t > m_actorIdToObjCountMap;
};
}

View file

@ -709,15 +709,13 @@ void Core::DebugCommandHandler::instance( char* data, Entity::Player &player, bo
}
else if( subCommand == "set" )
{
uint32_t instanceId;
uint32_t index;
uint32_t value;
sscanf( params.c_str(), "%d %d %d", &instanceId, &index, &value );
sscanf( params.c_str(), "%d %d", &index, &value );
auto pInstance = g_territoryMgr.getInstanceZonePtr( instanceId );
if( !pInstance )
auto instance = boost::dynamic_pointer_cast< InstanceContent >( player.getCurrentZone() );
if( !instance )
return;
auto instance = boost::dynamic_pointer_cast< InstanceContent >( pInstance );
instance->setVar( static_cast< uint8_t >( index ), static_cast< uint8_t >( value ) );
}
@ -738,6 +736,30 @@ void Core::DebugCommandHandler::instance( char* data, Entity::Player &player, bo
obj->setState( state );
}
else if( subCommand == "seq" )
{
uint8_t seq;
sscanf( params.c_str(), "%hhu", &seq );
auto instance = boost::dynamic_pointer_cast< InstanceContent >( player.getCurrentZone() );
if( !instance )
return;
instance->setSequence( seq );
}
else if( subCommand == "branch" )
{
uint8_t branch;
sscanf( params.c_str(), "%hhu", &branch );
auto instance = boost::dynamic_pointer_cast< InstanceContent >( player.getCurrentZone() );
if( !instance )
return;
instance->setBranch( branch );
}
else if( subCommand == "festival" )
{
uint32_t festivalId;

View file

@ -168,3 +168,13 @@ void Core::Event::Director::setDirectorUI8JH( uint8_t value )
{
m_unionData.ui8lh.UI8JH = value;
}
void Core::Event::Director::setDirectorBranch( uint8_t value )
{
m_branch = value;
}
void Core::Event::Director::setDirectorSequence( uint8_t value )
{
m_sequence = value;
}

View file

@ -72,6 +72,9 @@ public:
void setDirectorUI8JL( uint8_t value );
void setDirectorUI8JH( uint8_t value );
void setDirectorSequence( uint8_t value );
void setDirectorBranch( uint8_t value );
private:
/*! Id of the content of the director */
uint16_t m_contentId;

View file

@ -221,6 +221,27 @@ void Core::InstanceContent::setVar( uint8_t index, uint8_t value )
}
// todo: genericise this?
for( const auto &playerIt : m_playerMap )
{
sendDirectorVars( *playerIt.second );
}
}
void Core::InstanceContent::setSequence( uint8_t value )
{
setDirectorSequence( value );
for( const auto &playerIt : m_playerMap )
{
sendDirectorVars( *playerIt.second );
}
}
void Core::InstanceContent::setBranch( uint8_t value )
{
setDirectorBranch( value );
for( const auto &playerIt : m_playerMap )
{
sendDirectorVars( *playerIt.second );
@ -254,6 +275,8 @@ void Core::InstanceContent::onBeforeEnterTerritory( Core::Entity::Player &player
player.setRot( PI );
player.setPos( { 0.f, 0.f, 0.f } );
}
player.resetObjSpawnIndex( );
}
Core::Entity::EventObjectPtr Core::InstanceContent::getEObjByName( const std::string &name )

View file

@ -41,6 +41,8 @@ public:
void onRegisterEObj( Entity::EventObjectPtr object ) override;
void setVar( uint8_t index, uint8_t value );
void setSequence( uint8_t value );
void setBranch( uint8_t value );
boost::shared_ptr< Core::Data::InstanceContent > getInstanceContentInfo() const;