From ac9845f827c9f63cdf0699647276e586dc0611ed Mon Sep 17 00:00:00 2001 From: Mordred Date: Sat, 7 Jul 2018 00:10:16 +0200 Subject: [PATCH] Some movement improvements, still not perfect.. baby steps... --- src/common/Common.h | 20 ++- src/servers/sapphire_zone/Actor/Player.cpp | 3 +- src/servers/sapphire_zone/Actor/Player.h | 9 ++ .../Network/Handlers/PacketHandlers.cpp | 134 ++++++------------ 4 files changed, 71 insertions(+), 95 deletions(-) diff --git a/src/common/Common.h b/src/common/Common.h index da5f6a6f..8088c90b 100644 --- a/src/common/Common.h +++ b/src/common/Common.h @@ -189,14 +189,20 @@ namespace Common { }; - enum MoveType : uint16_t + enum MoveType : uint8_t { - Run = 0x00, - Walk = 0x02, - Strafe = 0x04, - Jump = 0x100, - Fall = 0x400, - Land = 0x200, + Running = 0x00, + Walking = 0x02, + Strafing = 0x04, + Jumping = 0x10, + BackWalk = Walking | Strafing, + }; + + enum MoveState : uint8_t + { + None = 0x00, + Land = 0x02, + Fall = 0x04, }; struct QuestActive diff --git a/src/servers/sapphire_zone/Actor/Player.cpp b/src/servers/sapphire_zone/Actor/Player.cpp index 8621da64..f8df9442 100644 --- a/src/servers/sapphire_zone/Actor/Player.cpp +++ b/src/servers/sapphire_zone/Actor/Player.cpp @@ -68,7 +68,8 @@ Core::Entity::Player::Player() : m_markedForRemoval( false ), m_mount( 0 ), m_directorInitialized( false ), - m_onEnterEventDone( false ) + m_onEnterEventDone( false ), + m_bJumping( false ) { m_id = 0; m_currentStance = Stance::Passive; diff --git a/src/servers/sapphire_zone/Actor/Player.h b/src/servers/sapphire_zone/Actor/Player.h index 2607852e..fbfa96fc 100644 --- a/src/servers/sapphire_zone/Actor/Player.h +++ b/src/servers/sapphire_zone/Actor/Player.h @@ -595,6 +595,13 @@ public: /*! checks if a spawn index is valid */ bool isObjSpawnIndexValid( uint8_t index ); + + uint64_t m_lastMoveTime; + + uint8_t m_lastMoveflag; + + bool m_bJumping; + private: uint32_t m_lastWrite; uint32_t m_lastPing; @@ -613,6 +620,8 @@ private: private: + + Common::FFXIVARR_POSITION3 m_prevPos; uint32_t m_prevZoneType; uint32_t m_prevZoneId; diff --git a/src/servers/sapphire_zone/Network/Handlers/PacketHandlers.cpp b/src/servers/sapphire_zone/Network/Handlers/PacketHandlers.cpp index 7d400df5..4e1d36f9 100644 --- a/src/servers/sapphire_zone/Network/Handlers/PacketHandlers.cpp +++ b/src/servers/sapphire_zone/Network/Handlers/PacketHandlers.cpp @@ -8,8 +8,12 @@ #include #include #include +#include #include + +#include + #include "Network/GameConnection.h" #include "Zone/TerritoryMgr.h" @@ -149,37 +153,12 @@ void Core::Network::GameConnection::updatePositionHandler( const Core::Network:: auto flags = *reinterpret_cast< uint16_t* >( ©.data[0x18] ); memcpy( &IPC_OP_019AB, &flags, 2 ); - auto flags1 = *reinterpret_cast< uint32_t* >( ©.data[0x14] ); + auto flags1 = *reinterpret_cast< uint32_t* >( ©.data[0x18] ); memcpy( &IPC_OP_019A, &flags1, 4 ); - //g_log.Log(LoggingSeverity::debug, "" + boost::lexical_cast((int)IPC_OP_019AB.bit1) - // + boost::lexical_cast((int)IPC_OP_019AB.bit2) - // + boost::lexical_cast((int)IPC_OP_019AB.bit3) - // + boost::lexical_cast((int)IPC_OP_019AB.bit4) - // + boost::lexical_cast((int)IPC_OP_019AB.bit5) - // + boost::lexical_cast((int)IPC_OP_019AB.bit6) - // + boost::lexical_cast((int)IPC_OP_019AB.bit7) - // + boost::lexical_cast((int)IPC_OP_019AB.bit8) - // + boost::lexical_cast((int)IPC_OP_019AB.bit9) - // + boost::lexical_cast((int)IPC_OP_019AB.bit10) - // + boost::lexical_cast((int)IPC_OP_019AB.bit11) - // + boost::lexical_cast((int)IPC_OP_019AB.bit12) - // + boost::lexical_cast((int)IPC_OP_019AB.bit13) - // + boost::lexical_cast((int)IPC_OP_019AB.bit14) - // + boost::lexical_cast((int)IPC_OP_019AB.bit15) - // + boost::lexical_cast((int)IPC_OP_019AB.bit16) - // + " " + boost::lexical_cast((int)flags)); - //g_log.Log(LoggingSeverity::debug, "\n" + boost::lexical_cast((int)IPC_OP_019A.specialMovement) + "\n" - // + boost::lexical_cast((int)IPC_OP_019A.strafe) + "\n" - // + boost::lexical_cast((int)IPC_OP_019A.moveBackward) + "\n" - // + boost::lexical_cast((int)IPC_OP_019A.strafeRight)); + auto pLog = g_fw.get< Logger >(); - //g_log.Log(LoggingSeverity::debug, pInPacket->toString()); - - //pInPacket->debugPrint(); - - ; bool bPosChanged = false; if( ( player.getPos().x != *reinterpret_cast< float* >( ©.data[0x1C] ) ) || ( player.getPos().y != *reinterpret_cast< float* >( ©.data[0x20] ) ) || @@ -200,88 +179,69 @@ void Core::Network::GameConnection::updatePositionHandler( const Core::Network:: if( !player.hasInRangeActor() ) return; - auto unk = *reinterpret_cast< uint8_t* >( ©.data[0x19] ); - - auto moveType = *reinterpret_cast< uint16_t* >( ©.data[0x18] ); + auto moveState = *reinterpret_cast< uint8_t* >( ©.data[0x19] ); + auto moveType = *reinterpret_cast< uint8_t* >( ©.data[0x18] ); uint8_t unk1 = 0; uint8_t unk2 = 0; - uint8_t unk3 = unk; + uint8_t unk3 = moveState; uint16_t unk4 = 0; // HACK: This part is hackish, we need to find out what all theese things really do. - switch( moveType ) - { - case MoveType::Strafe: + //pLog->debug( std::to_string( moveState ) + " -- moveState " ); + //pLog->debug( std::to_string( moveType ) + " -- moveType " ); + + if( moveType & MoveType::Strafing ) { + unk2 = 0x40; if( IPC_OP_019A.strafeRight == 1 ) unk1 = 0xbf; else unk1 = 0x5f; unk4 = 0x3C; - break; } - case 6: + if( moveType & MoveType::Walking ) + { + unk1 = 0x7F; + unk2 = 0x02; + unk3 = 0x00; + unk4 = 0x0518; + } + + if( moveType & MoveType::BackWalk ) { - unk1 = 0xFF; unk2 = 0x06; + unk1 = 0xFF; unk4 = 0x18; - break; } - // case MoveType::Land: - // { - // unk1 = 0x7F; - // //unk2 = 0x40; - // unk4 = 0x3C; - // break; - // } - - // case MoveType::Jump: - // { - // unk1 = 0x7F; - // if(unk == 0x01) - // { - // // unk2 = 0x20; - // //unk4 = 0x32; - // unk4 = 0x32; - // } - // else - // { - // // unk2 = 0xA0; - // unk4 = 0x3C; - // } - // - // break; - // } - // case MoveType::Fall: - // { - // unk1 = 0x7F; - // //unk2 = 0xA0; - // unk4 = 0x3C; - // - // break; - // } - default: + if( moveType & MoveType::Running ) { - if( static_cast< int32_t >( IPC_OP_019A.moveBackward ) ) - { - unk1 = 0xFF; - unk2 = 0x06; - unk4 = 0x18; // animation speed? - } - else - { - unk1 = 0x7F; - unk4 = 0x3C; // animation speed? - } - - break; - } + unk1 = 0x7F; + unk4 = 0x3C; } - auto movePacket = boost::make_shared< MoveActorPacket >( player, unk1, unk2, unk3, unk4 ); + if( moveType & MoveType::Jumping ) + { + + unk1 = 0x3F; + unk2 = 0x32; + unk4 = 0x5f18; + if( moveState == MoveState::Land ) + unk2 = 0x02; + + } + + uint64_t currentTime = Util::getTimeMs(); + + if( ( currentTime - player.m_lastMoveTime ) < 100 && player.m_lastMoveflag == moveState ) + return; + + player.m_lastMoveTime = currentTime; + player.m_lastMoveflag = moveState; + + auto movePacket = boost::make_shared< MoveActorPacket >( player, unk1, unk2, moveState, unk4 ); player.sendToInRangeSet( movePacket ); }