From 3a71d90e71b4bf8871588c3d823491a008591974 Mon Sep 17 00:00:00 2001 From: Mordred Date: Sat, 18 Feb 2023 15:26:50 +0100 Subject: [PATCH] Fixing some array sizes and defining them in common --- src/api/PlayerMinimal.cpp | 20 ++++++++-------- src/common/Common.h | 13 +++++++++- .../Network/PacketDef/Zone/ServerZoneDef.h | 2 +- src/lobby/GameConnection.cpp | 2 +- src/lobby/LobbyPacketContainer.cpp | 4 ++-- src/world/Actor/Player.h | 24 +++++++++---------- src/world/Manager/DebugCommandMgr.cpp | 7 ++---- .../PacketWrappers/PlayerSetupPacket.h | 2 +- 8 files changed, 41 insertions(+), 33 deletions(-) diff --git a/src/api/PlayerMinimal.cpp b/src/api/PlayerMinimal.cpp index 81e64e31..e1ab32e2 100644 --- a/src/api/PlayerMinimal.cpp +++ b/src/api/PlayerMinimal.cpp @@ -89,7 +89,7 @@ std::string PlayerMinimal::getInfoJson() // class levels auto levelsArray = nlohmann::json(); - for( int i = 0; i < Common::CLASSJOB_SLOTS; ++i ) + for( int i = 0; i < Common::ARRSIZE_CLASSJOB; ++i ) { // these must be strings levelsArray.push_back( std::to_string( m_classMap[ i ] ) ); @@ -186,16 +186,16 @@ void PlayerMinimal::saveAsNew() { std::vector< uint8_t > customize( 26 ); - std::vector< uint8_t > howTo( 33 ); - std::vector< uint8_t > aetherytes( 16 ); - std::vector< uint8_t > discovery( 421 ); - std::vector< uint8_t > questComplete( 342 ); - std::vector< uint8_t > unlocks( 64 ); - std::vector< uint8_t > mountGuide( 15 ); - std::vector< uint8_t > orchestrion( 40 ); + std::vector< uint8_t > howTo( Common::ARRSIZE_HOWTO ); + std::vector< uint8_t > aetherytes( Common::ARRSIZE_AETHERYTES ); + std::vector< uint8_t > discovery( Common::ARRSIZE_DISCOVERY ); + std::vector< uint8_t > questComplete( Common::ARRSIZE_QUESTCOMPLETE ); + std::vector< uint8_t > unlocks( Common::ARRSIZE_UNLOCKS ); + std::vector< uint8_t > mountGuide( Common::ARRSIZE_MOUNTS ); + std::vector< uint8_t > orchestrion( Common::ARRSIZE_ORCHESTRION ); std::vector< uint8_t > modelEquip( 40 ); std::vector< uint8_t > questTracking8( 10 ); - std::vector< uint8_t > monsterNote( 41 ); + std::vector< uint8_t > monsterNote( sizeof( Common::HuntingLogEntry ) ); std::vector< int16_t > questTracking = { -1, -1, -1, -1, -1 }; memset( questComplete.data(), 0, questComplete.size() ); @@ -314,7 +314,7 @@ void PlayerMinimal::saveAsNew() auto stmtMonsterNote = g_charaDb.getPreparedStatement( Db::ZoneDbStatements::CHARA_MONSTERNOTE_INS ); stmtMonsterNote->setUInt64( 1, m_characterId ); - for( uint8_t i = 1; i <= 12; ++i ) + for( uint8_t i = 1; i <= Common::ARRSIZE_MONSTERNOTE; ++i ) stmtMonsterNote->setBinary( i + 1, monsterNote ); g_charaDb.directExecute( stmtMonsterNote ); diff --git a/src/common/Common.h b/src/common/Common.h index 52f19554..f3e8f1d6 100644 --- a/src/common/Common.h +++ b/src/common/Common.h @@ -25,7 +25,18 @@ namespace Sapphire::Common const uint8_t CURRENT_EXPANSION_ID = 1; const uint8_t CLASSJOB_TOTAL = 34; - const uint8_t CLASSJOB_SLOTS = 23; + + const uint16_t ARRSIZE_CLASSJOB = 23u; + const uint16_t ARRSIZE_TITLELIST = 48u; + const uint16_t ARRSIZE_HOWTO = 32u; + const uint16_t ARRSIZE_MINIONS = 28u; + const uint16_t ARRSIZE_MOUNTS = 9u; + const uint16_t ARRSIZE_DISCOVERY = 400u; + const uint16_t ARRSIZE_QUESTCOMPLETE = 342u; + const uint16_t ARRSIZE_AETHERYTES = 12u; + const uint16_t ARRSIZE_UNLOCKS = 64u; + const uint16_t ARRSIZE_ORCHESTRION = 40u; + const uint16_t ARRSIZE_MONSTERNOTE = 12u; const uint8_t TOWN_COUNT = 6; diff --git a/src/common/Network/PacketDef/Zone/ServerZoneDef.h b/src/common/Network/PacketDef/Zone/ServerZoneDef.h index 8cbf8c2e..29c18ae2 100644 --- a/src/common/Network/PacketDef/Zone/ServerZoneDef.h +++ b/src/common/Network/PacketDef/Zone/ServerZoneDef.h @@ -816,7 +816,7 @@ namespace Sapphire::Network::Packets::WorldPackets::Server */ struct FFXIVIpcTitleList : FFXIVIpcBasePacket< TitleList > { - uint8_t TitleFlagsArray[32]; + uint8_t TitleFlagsArray[48]; }; /** diff --git a/src/lobby/GameConnection.cpp b/src/lobby/GameConnection.cpp index b0a7e753..c58bc1a7 100644 --- a/src/lobby/GameConnection.cpp +++ b/src/lobby/GameConnection.cpp @@ -567,7 +567,7 @@ void Lobby::GameConnection::handlePackets( const Network::Packets::FFXIVARR_PACK BlowFish blowfish; blowfish.initialize( m_encKey, 0x10 ); blowfish.Decode( ( uint8_t* ) ( &inPacket.data[ 0 ] ), ( uint8_t* ) ( &inPacket.data[ 0 ] ), - ( inPacket.data.size() ) - 0x10 ); + static_cast< uint32_t >( inPacket.data.size() ) - 0x10 ); } switch( inPacket.segHdr.type ) diff --git a/src/lobby/LobbyPacketContainer.cpp b/src/lobby/LobbyPacketContainer.cpp index c396db1d..7456249e 100644 --- a/src/lobby/LobbyPacketContainer.cpp +++ b/src/lobby/LobbyPacketContainer.cpp @@ -32,10 +32,10 @@ void LobbyPacketContainer::addPacket( FFXIVPacketBasePtr pEntry ) { BlowFish blowfish; blowfish.initialize( m_encKey, 0x10 ); - blowfish.Encode( m_dataBuf.data() + m_header.size + 0x10, m_dataBuf.data() + m_header.size + 0x10, pEntry->getSize() - 0x10 ); + blowfish.Encode( m_dataBuf.data() + m_header.size + 0x10, m_dataBuf.data() + m_header.size + 0x10, static_cast< uint32_t >( pEntry->getSize() ) - 0x10 ); } - m_header.size += pEntry->getSize(); + m_header.size += static_cast< uint32_t >( pEntry->getSize() ); m_header.count++; } diff --git a/src/world/Actor/Player.h b/src/world/Actor/Player.h index a188f879..8db015d5 100644 --- a/src/world/Actor/Player.h +++ b/src/world/Actor/Player.h @@ -25,19 +25,19 @@ namespace Sapphire::Entity class Player : public Chara { public: - using TitleList = std::array< uint8_t, 48 >; - using HowToList = std::array< uint8_t, 34 >; - using MinionList = std::array< uint8_t, 40 >; - using MountList = std::array< uint8_t, 22 >; - using QuestComplete = std::array< uint8_t, 342 >; - using Discovery = std::array< uint8_t, 400 >; - using AetheryteList = std::array< uint8_t, 21 >; - using UnlockList = std::array< uint8_t, 64 >; - using OrchestrionList = std::array< uint8_t, 40 >; + using TitleList = std::array< uint8_t, Common::ARRSIZE_TITLELIST >; + using HowToList = std::array< uint8_t, Common::ARRSIZE_HOWTO >; + using MinionList = std::array< uint8_t, Common::ARRSIZE_MINIONS >; + using MountList = std::array< uint8_t, Common::ARRSIZE_MOUNTS >; + using QuestComplete = std::array< uint8_t, Common::ARRSIZE_QUESTCOMPLETE >; + using Discovery = std::array< uint8_t, Common::ARRSIZE_DISCOVERY >; + using AetheryteList = std::array< uint8_t, Common::ARRSIZE_AETHERYTES >; + using UnlockList = std::array< uint8_t, Common::ARRSIZE_UNLOCKS >; + using OrchestrionList = std::array< uint8_t, Common::ARRSIZE_ORCHESTRION >; using StateFlags = std::array< uint8_t, 12 >; - using ClassList = std::array< uint16_t, 28 >; - using ExpList = std::array< uint32_t, 28 >; + using ClassList = std::array< uint16_t, Common::ARRSIZE_CLASSJOB >; + using ExpList = std::array< uint32_t, Common::ARRSIZE_CLASSJOB >; struct AchievementData { std::array< uint8_t, 2048 / 8 > unlockList; @@ -994,7 +994,7 @@ namespace Sapphire::Entity Common::Util::SpawnIndexAllocator< uint8_t > m_objSpawnIndexAllocator; Common::Util::SpawnIndexAllocator< uint8_t > m_actorSpawnIndexAllocator; - std::array< Common::HuntingLogEntry, 12 > m_huntingLogEntries{}; + std::array< Common::HuntingLogEntry, Common::ARRSIZE_MONSTERNOTE > m_huntingLogEntries{}; FriendListIDVec m_friendList{}; FriendListDataVec m_friendInviteList{}; diff --git a/src/world/Manager/DebugCommandMgr.cpp b/src/world/Manager/DebugCommandMgr.cpp index 5444b442..313d2c1e 100644 --- a/src/world/Manager/DebugCommandMgr.cpp +++ b/src/world/Manager/DebugCommandMgr.cpp @@ -545,9 +545,6 @@ void DebugCommandMgr::add( char* data, Entity::Player& player, std::shared_ptr< auto sequence = pCurrentZone->getNextEffectResultId(); effectPacket->setSequence( sequence ); -// effectPacket->setAnimationId( param1 ); -// effectPacket->setEffectFlags( 0 ); - server().queueForPlayer( player.getCharacterId(), effectPacket ); } else if( subCommand == "achvGeneral" ) @@ -597,8 +594,8 @@ void DebugCommandMgr::get( char* data, Entity::Player& player, std::shared_ptr< int16_t map_id = exdData.getRow< Excel::TerritoryType >( player.getTerritoryTypeId() )->data().Map; PlayerMgr::sendServerNotice( player, "Pos:\n {0}\n {1}\n {2}\n {3}\n MapId: {4}\n ZoneId:{5}", - player.getPos().x, player.getPos().y, player.getPos().z, - player.getRot(), map_id, player.getTerritoryTypeId() ); + player.getPos().x, player.getPos().y, player.getPos().z, + player.getRot(), map_id, player.getTerritoryTypeId() ); } else { diff --git a/src/world/Network/PacketWrappers/PlayerSetupPacket.h b/src/world/Network/PacketWrappers/PlayerSetupPacket.h index 221c09c1..3e7d4558 100644 --- a/src/world/Network/PacketWrappers/PlayerSetupPacket.h +++ b/src/world/Network/PacketWrappers/PlayerSetupPacket.h @@ -49,7 +49,7 @@ namespace Sapphire::Network::Packets::WorldPackets::Server memcpy( m_data.Aetheryte, player.getAetheryteArray().data(), sizeof( m_data.Aetheryte ) ); // Set the class levels and exp. - for( uint8_t i = 0; i < Common::CLASSJOB_SLOTS; ++i ) + for( uint8_t i = 0; i < Common::ARRSIZE_CLASSJOB; ++i ) { m_data.Lv[ i ] = player.getClassArray()[ i ]; m_data.Exp[ i ] = player.getExpArray()[ i ];