2021-12-05 17:54:36 +00:00
# include "GameMessages.h"
# include "User.h"
# include "Entity.h"
2023-09-21 01:06:28 +00:00
# include "BitStreamUtils.h"
2021-12-05 17:54:36 +00:00
# include "BitStream.h"
# include "Game.h"
# include "SlashCommandHandler.h"
# include "NiPoint3.h"
# include "NiQuaternion.h"
2023-10-21 23:31:55 +00:00
# include "Logger.h"
2021-12-05 17:54:36 +00:00
# include "GeneralUtils.h"
# include "Character.h"
# include "EntityManager.h"
# include "Database.h"
# include "dServer.h"
2024-01-05 12:31:22 +00:00
# include "ObjectIDManager.h"
2021-12-05 17:54:36 +00:00
# include "CppScripts.h"
# include "UserManager.h"
# include "ZoneInstanceManager.h"
# include "WorldPackets.h"
# include "Item.h"
# include "ZCompression.h"
# include "dConfig.h"
# include "TeamManager.h"
# include "ChatPackets.h"
2023-08-18 19:14:40 +00:00
# include "MultiZoneEntranceComponent.h"
2022-09-02 18:49:19 +00:00
# include "eUnequippableActiveType.h"
2023-01-07 05:17:05 +00:00
# include "eMovementPlatformState.h"
# include "LeaderboardManager.h"
2023-05-13 22:22:00 +00:00
# include "Amf3.h"
2023-01-07 05:17:05 +00:00
# include "Loot.h"
2023-01-22 23:38:47 +00:00
# include "eRacingTaskParam.h"
# include "eMissionTaskType.h"
# include "eMissionState.h"
2023-04-25 18:17:40 +00:00
# include "eObjectBits.h"
2023-03-25 10:26:39 +00:00
# include "eTriggerEventType.h"
2023-05-02 22:39:21 +00:00
# include "eMatchUpdate.h"
# include "eCyclingMode.h"
# include "eCinematicEvent.h"
# include "eQuickBuildFailReason.h"
# include "eControlScheme.h"
# include "eStateChangeType.h"
2023-05-03 21:38:32 +00:00
# include "eConnectionType.h"
2023-11-22 02:04:44 +00:00
# include "ePlayerFlag.h"
2021-12-05 17:54:36 +00:00
# include <sstream>
# include <future>
# include <chrono>
# include "RakString.h"
2024-01-05 12:33:52 +00:00
# include "httplib.h" //sorry not sorry.
2021-12-05 17:54:36 +00:00
//CDB includes:
# include "CDClientManager.h"
# include "CDEmoteTable.h"
//Component includes:
# include "ControllablePhysicsComponent.h"
# include "CharacterComponent.h"
# include "MissionOfferComponent.h"
# include "MissionComponent.h"
# include "DestroyableComponent.h"
# include "ScriptComponent.h"
2023-12-29 04:24:30 +00:00
# include "QuickBuildComponent.h"
2021-12-05 17:54:36 +00:00
# include "VendorComponent.h"
2022-12-18 15:46:04 +00:00
# include "InventoryComponent.h"
2021-12-05 17:54:36 +00:00
# include "RocketLaunchpadControlComponent.h"
# include "PropertyEntranceComponent.h"
# include "MovingPlatformComponent.h"
# include "PetComponent.h"
# include "ModuleAssemblyComponent.h"
2023-12-04 15:20:41 +00:00
# include "HavokVehiclePhysicsComponent.h"
2023-05-13 23:22:13 +00:00
# include "RenderComponent.h"
2021-12-05 17:54:36 +00:00
# include "PossessableComponent.h"
# include "PossessorComponent.h"
# include "RacingControlComponent.h"
# include "RailActivatorComponent.h"
2022-07-24 18:04:02 +00:00
# include "LevelProgressionComponent.h"
2023-08-04 02:44:03 +00:00
# include "DonationVendorComponent.h"
2024-01-14 19:10:13 +00:00
# include "GhostComponent.h"
2024-02-25 07:47:05 +00:00
# include "AchievementVendorComponent.h"
2021-12-05 17:54:36 +00:00
// Message includes:
# include "dZoneManager.h"
# include "PropertyDataMessage.h"
# include "PropertyManagementComponent.h"
# include "PropertyVendorComponent.h"
# include "PropertySelectQueryProperty.h"
# include "TradingManager.h"
2022-10-31 22:32:07 +00:00
# include "ControlBehaviors.h"
# include "AMFDeserialize.h"
2022-11-28 00:48:46 +00:00
# include "eBlueprintSaveResponseType.h"
2024-11-18 00:39:44 +00:00
# include "eAnimationFlags.h"
2023-05-13 22:22:00 +00:00
# include "AmfSerialize.h"
2023-03-04 07:16:37 +00:00
# include "eReplicaComponentType.h"
2024-11-18 00:39:44 +00:00
# include "MessageType/Client.h"
# include "MessageType/Game.h"
2024-01-08 23:32:09 +00:00
# include "ePetAbilityType.h"
2023-05-11 00:26:04 +00:00
# include "ActivityManager.h"
2024-01-13 09:40:56 +00:00
# include "PlayerManager.h"
2024-02-25 07:47:05 +00:00
# include "eVendorTransactionResult.h"
2024-05-25 02:35:14 +00:00
# include "eReponseMoveItemBetweenInventoryTypeCode.h"
2021-12-05 17:54:36 +00:00
2023-03-17 14:36:21 +00:00
# include "CDComponentsRegistryTable.h"
# include "CDObjectsTable.h"
2024-05-31 04:53:13 +00:00
# include "eItemType.h"
2023-03-17 14:36:21 +00:00
2021-12-05 17:54:36 +00:00
void GameMessages : : SendFireEventClientSide ( const LWOOBJID & objectID , const SystemAddress & sysAddr , std : : u16string args , const LWOOBJID & object , int64_t param1 , int param2 , const LWOOBJID & sender ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : FIRE_EVENT_CLIENT_SIDE ) ;
2021-12-05 17:54:36 +00:00
//bitStream.Write(args);
uint32_t argSize = args . size ( ) ;
bitStream . Write ( argSize ) ;
for ( uint32_t k = 0 ; k < argSize ; k + + ) {
2023-12-24 00:11:00 +00:00
bitStream . Write < uint16_t > ( args [ k ] ) ;
2021-12-05 17:54:36 +00:00
}
bitStream . Write ( object ) ;
bitStream . Write0 ( ) ;
//bitStream.Write(param1);
bitStream . Write0 ( ) ;
//bitStream.Write(param2);
bitStream . Write ( sender ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2023-06-18 07:00:36 +00:00
void GameMessages : : SendTeleport ( const LWOOBJID & objectID , const NiPoint3 & pos , const NiQuaternion & rot , const SystemAddress & sysAddr , bool bSetRotation ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : TELEPORT ) ;
2021-12-05 17:54:36 +00:00
bool bIgnoreY = ( pos . y = = 0.0f ) ;
bool bUseNavmesh = false ;
bool bSkipAllChecks = false ;
//float w = 1.0f;
//float x = 0.0f;
//float y = 0.0f;
//float z = 0.0f;
bitStream . Write ( bIgnoreY ) ;
bitStream . Write ( bSetRotation ) ;
bitStream . Write ( bSkipAllChecks ) ;
bitStream . Write ( pos . x ) ;
bitStream . Write ( pos . y ) ;
bitStream . Write ( pos . z ) ;
bitStream . Write ( bUseNavmesh ) ;
bitStream . Write ( rot . w ! = 1.0f ) ;
if ( rot . w ! = 1.0f ) bitStream . Write ( rot . w ) ;
bitStream . Write ( rot . x ) ;
bitStream . Write ( rot . y ) ;
bitStream . Write ( rot . z ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendPlayAnimation ( Entity * entity , const std : : u16string & animationName , float fPriority , float fScale ) {
if ( ! entity ) {
2023-10-21 23:31:55 +00:00
LOG ( " Trying to play animation, but entity var is nullptr! " ) ;
2021-12-05 17:54:36 +00:00
return ;
}
//Stolen from the old DLU codebase as the new one's autogenerated code doesn't work properly for animationIDs longer than 6 characters.
CBITSTREAM ;
CMSGHEADER ;
std : : string sAnimationID = GeneralUtils : : UTF16ToWTF8 ( animationName ) ;
uint32_t animationIDLength = sAnimationID . size ( ) ;
bool bExpectAnimToExist = true ;
bool bPlayImmediate = false ;
bool bTriggerOnCompleteMsg = false ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PLAY_ANIMATION ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( animationIDLength ) ;
2023-09-21 01:06:28 +00:00
bitStream . Write ( LUWString ( animationName , animationIDLength ) ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bExpectAnimToExist ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
bitStream . Write ( bPlayImmediate ) ;
bitStream . Write ( bTriggerOnCompleteMsg ) ;
bitStream . Write ( fPriority ! = 0.0f ) ;
if ( fPriority ! = 0.0f ) bitStream . Write ( fPriority ) ;
bitStream . Write ( fScale ! = 1.0f ) ;
if ( fScale ! = 1.0f ) bitStream . Write ( fScale ) ;
SEND_PACKET_BROADCAST ;
}
void GameMessages : : SendPlayerReady ( Entity * entity , const SystemAddress & sysAddr ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PLAYER_READY ) ;
2021-12-05 17:54:36 +00:00
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendPlayerAllowedRespawn ( LWOOBJID entityID , bool doNotPromptRespawn , const SystemAddress & sysAddr ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
bitStream . Write ( entityID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_PLAYER_ALLOWED_RESPAWN ) ;
2022-07-23 02:58:20 +00:00
bitStream . Write ( doNotPromptRespawn ) ;
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendInvalidZoneTransferList ( Entity * entity , const SystemAddress & sysAddr , const std : : u16string & feedbackURL , const std : : u16string & invalidMapTransferList , bool feedbackOnExit , bool feedbackOnInvalidTransfer ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : INVALID_ZONE_TRANSFER_LIST ) ;
2021-12-05 17:54:36 +00:00
uint32_t CustomerFeedbackURLLength = feedbackURL . size ( ) ;
bitStream . Write ( CustomerFeedbackURLLength ) ;
for ( uint32_t k = 0 ; k < CustomerFeedbackURLLength ; k + + ) {
2023-12-24 00:11:00 +00:00
bitStream . Write < uint16_t > ( feedbackURL [ k ] ) ;
2021-12-05 17:54:36 +00:00
}
uint32_t InvalidMapTransferListLength = invalidMapTransferList . size ( ) ;
bitStream . Write ( InvalidMapTransferListLength ) ;
for ( uint32_t k = 0 ; k < InvalidMapTransferListLength ; k + + ) {
2023-12-24 00:11:00 +00:00
bitStream . Write < uint16_t > ( invalidMapTransferList [ k ] ) ;
2021-12-05 17:54:36 +00:00
}
bitStream . Write ( feedbackOnExit ) ;
bitStream . Write ( feedbackOnInvalidTransfer ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendKnockback ( const LWOOBJID & objectID , const LWOOBJID & caster , const LWOOBJID & originator , int knockBackTimeMS , const NiPoint3 & vector ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : KNOCKBACK ) ;
2021-12-05 17:54:36 +00:00
bool casterFlag = caster ! = LWOOBJID_EMPTY ;
bool originatorFlag = originator ! = LWOOBJID_EMPTY ;
bool knockBackTimeMSFlag = knockBackTimeMS ! = 0 ;
bitStream . Write ( casterFlag ) ;
if ( casterFlag ) bitStream . Write ( caster ) ;
bitStream . Write ( originatorFlag ) ;
if ( originatorFlag ) bitStream . Write ( originator ) ;
bitStream . Write ( knockBackTimeMSFlag ) ;
if ( knockBackTimeMSFlag ) bitStream . Write ( knockBackTimeMS ) ;
bitStream . Write ( vector ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET_BROADCAST ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendStartArrangingWithItem (
Entity * entity ,
const SystemAddress & sysAddr ,
bool bFirstTime ,
const LWOOBJID & buildAreaID ,
NiPoint3 buildStartPOS ,
int sourceBAG ,
const LWOOBJID & sourceID ,
LOT sourceLOT ,
int sourceTYPE ,
const LWOOBJID & targetID ,
LOT targetLOT ,
NiPoint3 targetPOS ,
int targetTYPE
) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : START_ARRANGING_WITH_ITEM ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bFirstTime ) ;
bitStream . Write ( buildAreaID ! = LWOOBJID_EMPTY ) ;
if ( buildAreaID ! = LWOOBJID_EMPTY ) bitStream . Write ( buildAreaID ) ;
bitStream . Write ( buildStartPOS ) ;
bitStream . Write ( sourceBAG ) ;
bitStream . Write ( sourceID ) ;
bitStream . Write ( sourceLOT ) ;
bitStream . Write ( sourceTYPE ) ;
bitStream . Write ( targetID ) ;
bitStream . Write ( targetLOT ) ;
bitStream . Write ( targetPOS ) ;
bitStream . Write ( targetTYPE ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendPlayerSetCameraCyclingMode ( const LWOOBJID & objectID , const SystemAddress & sysAddr ,
2022-07-28 13:39:57 +00:00
bool bAllowCyclingWhileDeadOnly , eCyclingMode cyclingMode ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PLAYER_SET_CAMERA_CYCLING_MODE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bAllowCyclingWhileDeadOnly ) ;
2023-05-02 22:39:21 +00:00
bitStream . Write ( cyclingMode ! = eCyclingMode : : ALLOW_CYCLE_TEAMMATES ) ;
if ( cyclingMode ! = eCyclingMode : : ALLOW_CYCLE_TEAMMATES ) {
bitStream . Write ( cyclingMode ) ;
2021-12-05 17:54:36 +00:00
}
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendPlayNDAudioEmitter ( Entity * entity , const SystemAddress & sysAddr , std : : string audioGUID ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PLAY_ND_AUDIO_EMITTER ) ;
2024-02-27 16:07:14 +00:00
bitStream . Write0 ( ) ; // callback message data {lwoobjid}
bitStream . Write0 ( ) ; // audio emitterid {uint32_t}
2021-12-05 17:54:36 +00:00
uint32_t length = audioGUID . size ( ) ;
bitStream . Write ( length ) ;
for ( uint32_t k = 0 ; k < length ; k + + ) {
2023-12-24 00:11:00 +00:00
bitStream . Write < char > ( audioGUID [ k ] ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-27 16:07:14 +00:00
bitStream . Write < uint32_t > ( 0 ) ; // size of NDAudioMetaEventName (then print the string like the guid)
bitStream . Write0 ( ) ; // result {bool}
bitStream . Write0 ( ) ; // m_TargetObjectIDForNDAudioCallbackMessages {lwoobjid}
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
SEND_PACKET_BROADCAST ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendStartPathing ( Entity * entity ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : START_PATHING ) ;
2021-12-05 17:54:36 +00:00
SEND_PACKET_BROADCAST ;
}
2023-12-23 07:53:21 +00:00
void GameMessages : : SendResetMissions ( Entity * entity , const SystemAddress & sysAddr , const int32_t missionid ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : RESET_MISSIONS ) ;
2023-12-23 07:53:21 +00:00
bitStream . Write ( missionid ! = - 1 ) ;
if ( missionid ! = - 1 ) bitStream . Write ( missionid ) ;
SEND_PACKET ;
}
2021-12-05 17:54:36 +00:00
void GameMessages : : SendPlatformResync ( Entity * entity , const SystemAddress & sysAddr , bool bStopAtDesiredWaypoint ,
2022-07-28 13:39:57 +00:00
int iIndex , int iDesiredWaypointIndex , int nextIndex ,
2023-01-07 05:17:05 +00:00
eMovementPlatformState movementState ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
const auto lot = entity - > GetLOT ( ) ;
2021-12-05 17:54:36 +00:00
2024-05-10 14:22:26 +00:00
if ( lot = = 12341 | | lot = = 5027 | | lot = = 5028 | | lot = = 14335 | | lot = = 14447 | | lot = = 14449 | | lot = = 11306 | | lot = = 11308 ) {
iDesiredWaypointIndex = ( lot = = 11306 | | lot = = 11308 ) ? 1 : 0 ;
2021-12-05 17:54:36 +00:00
iIndex = 0 ;
nextIndex = 0 ;
bStopAtDesiredWaypoint = true ;
2023-01-07 05:17:05 +00:00
movementState = eMovementPlatformState : : Stationary ;
2021-12-05 17:54:36 +00:00
}
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PLATFORM_RESYNC ) ;
2021-12-05 17:54:36 +00:00
bool bReverse = false ;
int eCommand = 0 ;
int eUnexpectedCommand = 0 ;
float fIdleTimeElapsed = 0.0f ;
float fMoveTimeElapsed = 0.0f ;
float fPercentBetweenPoints = 0.0f ;
2024-01-29 07:53:12 +00:00
NiPoint3 ptUnexpectedLocation = NiPoint3Constant : : ZERO ;
NiQuaternion qUnexpectedRotation = NiQuaternionConstant : : IDENTITY ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bReverse ) ;
bitStream . Write ( bStopAtDesiredWaypoint ) ;
bitStream . Write ( eCommand ) ;
2023-12-28 04:18:20 +00:00
bitStream . Write ( static_cast < int32_t > ( movementState ) ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( eUnexpectedCommand ) ;
bitStream . Write ( fIdleTimeElapsed ) ;
bitStream . Write ( fMoveTimeElapsed ) ;
bitStream . Write ( fPercentBetweenPoints ) ;
bitStream . Write ( iDesiredWaypointIndex ) ;
bitStream . Write ( iIndex ) ;
bitStream . Write ( nextIndex ) ;
bitStream . Write ( ptUnexpectedLocation . x ) ;
bitStream . Write ( ptUnexpectedLocation . y ) ;
bitStream . Write ( ptUnexpectedLocation . z ) ;
2024-01-29 07:53:12 +00:00
bitStream . Write ( qUnexpectedRotation ! = NiQuaternionConstant : : IDENTITY ) ;
if ( qUnexpectedRotation ! = NiQuaternionConstant : : IDENTITY ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( qUnexpectedRotation . x ) ;
bitStream . Write ( qUnexpectedRotation . y ) ;
bitStream . Write ( qUnexpectedRotation . z ) ;
bitStream . Write ( qUnexpectedRotation . w ) ;
}
2024-05-20 07:43:57 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendRestoreToPostLoadStats ( Entity * entity , const SystemAddress & sysAddr ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : RESTORE_TO_POST_LOAD_STATS ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendServerDoneLoadingAllObjects ( Entity * entity , const SystemAddress & sysAddr ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SERVER_DONE_LOADING_ALL_OBJECTS ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2023-03-24 23:16:45 +00:00
void GameMessages : : SendChatModeUpdate ( const LWOOBJID & objectID , eGameMasterLevel level ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : UPDATE_CHAT_MODE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( level ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET_BROADCAST ;
2021-12-05 17:54:36 +00:00
}
2023-03-24 23:16:45 +00:00
void GameMessages : : SendGMLevelBroadcast ( const LWOOBJID & objectID , eGameMasterLevel level ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_GM_LEVEL ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write1 ( ) ;
bitStream . Write ( level ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET_BROADCAST ;
2021-12-05 17:54:36 +00:00
}
2022-04-23 11:14:55 +00:00
void GameMessages : : SendAddItemToInventoryClientSync ( Entity * entity , const SystemAddress & sysAddr , Item * item , const LWOOBJID & objectID , bool showFlyingLoot , int itemCount , LWOOBJID subKey , eLootSourceType lootSourceType ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : ADD_ITEM_TO_INVENTORY_CLIENT_SYNC ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( item - > GetBound ( ) ) ;
bitStream . Write ( item - > GetInfo ( ) . isBOE ) ;
bitStream . Write ( item - > GetInfo ( ) . isBOP ) ;
2023-05-02 22:39:21 +00:00
bitStream . Write ( lootSourceType ! = eLootSourceType : : NONE ) ; // Loot source
if ( lootSourceType ! = eLootSourceType : : NONE ) bitStream . Write ( lootSourceType ) ;
2021-12-05 17:54:36 +00:00
LWONameValue extraInfo ;
auto config = item - > GetConfig ( ) ;
2022-07-17 07:35:11 +00:00
2022-07-28 13:39:57 +00:00
for ( auto * data : config ) {
2021-12-05 17:54:36 +00:00
extraInfo . name + = GeneralUtils : : ASCIIToUTF16 ( data - > GetString ( ) ) + u " , " ;
}
if ( extraInfo . name . length ( ) > 0 ) extraInfo . name . pop_back ( ) ; // remove the last comma
2022-07-17 07:35:11 +00:00
bitStream . Write < uint32_t > ( extraInfo . name . size ( ) ) ;
2021-12-05 17:54:36 +00:00
if ( extraInfo . name . size ( ) > 0 ) {
for ( uint32_t i = 0 ; i < extraInfo . name . size ( ) ; + + i ) {
2023-12-24 00:11:00 +00:00
bitStream . Write < uint16_t > ( extraInfo . name [ i ] ) ;
2021-12-05 17:54:36 +00:00
}
2023-12-24 00:11:00 +00:00
bitStream . Write < uint16_t > ( 0x00 ) ;
2021-12-05 17:54:36 +00:00
}
bitStream . Write ( item - > GetLot ( ) ) ;
bitStream . Write ( subKey ! = LWOOBJID_EMPTY ) ;
if ( subKey ! = LWOOBJID_EMPTY ) bitStream . Write ( subKey ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
auto * inventory = item - > GetInventory ( ) ;
const auto inventoryType = inventory - > GetType ( ) ;
2022-07-17 07:35:11 +00:00
2022-04-23 12:13:06 +00:00
bitStream . Write ( inventoryType ! = eInventoryType : : ITEMS ) ;
if ( inventoryType ! = eInventoryType : : ITEMS ) bitStream . Write ( inventoryType ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( itemCount ! = 1 ) ;
if ( itemCount ! = 1 ) bitStream . Write ( itemCount ) ;
const auto count = item - > GetCount ( ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
bitStream . Write ( count ! = 0 ) ; //items total
if ( count ! = 0 ) bitStream . Write ( count ) ;
bitStream . Write ( objectID ) ;
bitStream . Write ( 0.0f ) ;
bitStream . Write ( 0.0f ) ;
bitStream . Write ( 0.0f ) ;
bitStream . Write ( showFlyingLoot ) ;
bitStream . Write ( item - > GetSlot ( ) ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2023-05-02 22:39:21 +00:00
void GameMessages : : SendNotifyClientFlagChange ( const LWOOBJID & objectID , uint32_t iFlagID , bool bFlag , const SystemAddress & sysAddr ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : NOTIFY_CLIENT_FLAG_CHANGE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bFlag ) ;
bitStream . Write ( iFlagID ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2023-05-02 22:39:21 +00:00
void GameMessages : : SendChangeObjectWorldState ( const LWOOBJID & objectID , eObjectWorldState state , const SystemAddress & sysAddr ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : CHANGE_OBJECT_WORLD_STATE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( state ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendOfferMission ( const LWOOBJID & entity , const SystemAddress & sysAddr , int32_t missionID , const LWOOBJID & offererID ) {
//You might be wondering.
//"Why are we sending it twice, once to a non-player object?
//Well, the first one (sent to the offerer) makes the client zoom into the object.
//The second, actually makes the UI pop up so you can be offered the mission.
//Why is it like this? Because LU isn't just a clown, it's the entire circus.
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( offererID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : OFFER_MISSION ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( missionID ) ;
bitStream . Write ( offererID ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
{
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( entity ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : OFFER_MISSION ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( missionID ) ;
bitStream . Write ( offererID ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
}
void GameMessages : : SendNotifyMission ( Entity * entity , const SystemAddress & sysAddr , int missionID , int missionState , bool sendingRewards ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : NOTIFY_MISSION ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( missionID ) ;
bitStream . Write ( missionState ) ;
bitStream . Write ( sendingRewards ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendNotifyMissionTask ( Entity * entity , const SystemAddress & sysAddr , int missionID , int taskMask , std : : vector < float > updates ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : NOTIFY_MISSION_TASK ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( missionID ) ;
bitStream . Write ( taskMask ) ;
2023-12-28 04:18:20 +00:00
bitStream . Write < unsigned char > ( updates . size ( ) ) ;
2021-12-05 17:54:36 +00:00
for ( uint32_t i = 0 ; i < updates . size ( ) ; + + i ) {
bitStream . Write ( updates [ i ] ) ;
}
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2022-02-03 06:50:02 +00:00
void GameMessages : : SendModifyLEGOScore ( Entity * entity , const SystemAddress & sysAddr , int64_t score , eLootSourceType sourceType ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : MODIFY_LEGO_SCORE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( score ) ;
2023-05-02 22:39:21 +00:00
bitStream . Write ( sourceType ! = eLootSourceType : : NONE ) ;
if ( sourceType ! = eLootSourceType : : NONE ) bitStream . Write ( sourceType ) ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2023-05-13 22:22:00 +00:00
void GameMessages : : SendUIMessageServerToSingleClient ( Entity * entity , const SystemAddress & sysAddr , const std : : string & message , AMFBaseValue & args ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : UI_MESSAGE_SERVER_TO_SINGLE_CLIENT ) ;
2021-12-05 17:54:36 +00:00
2023-05-13 22:22:00 +00:00
bitStream . Write < AMFBaseValue & > ( args ) ;
2021-12-05 17:54:36 +00:00
uint32_t strMessageNameLength = message . size ( ) ;
bitStream . Write ( strMessageNameLength ) ;
for ( uint32_t k = 0 ; k < strMessageNameLength ; k + + ) {
2023-12-24 00:11:00 +00:00
bitStream . Write < char > ( message [ k ] ) ;
2021-12-05 17:54:36 +00:00
}
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2024-01-18 08:10:52 +00:00
void GameMessages : : SendUIMessageServerToSingleClient ( const std : : string & message , AMFBaseValue & args , const SystemAddress & sysAddr ) {
CBITSTREAM ;
CMSGHEADER ;
LWOOBJID empty = 0 ;
bitStream . Write ( empty ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : UI_MESSAGE_SERVER_TO_ALL_CLIENTS ) ; // This is intentional to allow the server to send a ui message to a client via their system address.
2024-01-18 08:10:52 +00:00
bitStream . Write < AMFBaseValue & > ( args ) ;
uint32_t strMessageNameLength = message . size ( ) ;
bitStream . Write ( strMessageNameLength ) ;
for ( uint32_t k = 0 ; k < strMessageNameLength ; k + + ) {
bitStream . Write < char > ( message [ k ] ) ;
}
SEND_PACKET ;
}
2023-05-13 22:22:00 +00:00
void GameMessages : : SendUIMessageServerToAllClients ( const std : : string & message , AMFBaseValue & args ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
LWOOBJID empty = 0 ;
bitStream . Write ( empty ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : UI_MESSAGE_SERVER_TO_ALL_CLIENTS ) ;
2021-12-05 17:54:36 +00:00
2023-05-13 22:22:00 +00:00
bitStream . Write < AMFBaseValue & > ( args ) ;
2021-12-05 17:54:36 +00:00
uint32_t strMessageNameLength = message . size ( ) ;
bitStream . Write ( strMessageNameLength ) ;
for ( uint32_t k = 0 ; k < strMessageNameLength ; k + + ) {
2023-12-24 00:11:00 +00:00
bitStream . Write < char > ( message [ k ] ) ;
2021-12-05 17:54:36 +00:00
}
SEND_PACKET_BROADCAST ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendPlayEmbeddedEffectOnAllClientsNearObject ( Entity * entity , std : : u16string effectName , const LWOOBJID & fromObjectID , float radius ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PLAY_EMBEDDED_EFFECT_ON_ALL_CLIENTS_NEAR_OBJECT ) ;
2021-12-05 17:54:36 +00:00
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( effectName . length ( ) ) ;
2021-12-05 17:54:36 +00:00
for ( uint32_t k = 0 ; k < effectName . length ( ) ; k + + ) {
2023-12-24 00:11:00 +00:00
bitStream . Write < uint16_t > ( effectName [ k ] ) ;
2021-12-05 17:54:36 +00:00
}
bitStream . Write ( fromObjectID ) ;
bitStream . Write ( radius ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET_BROADCAST ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendPlayFXEffect ( Entity * entity , int32_t effectID , const std : : u16string & effectType , const std : : string & name , LWOOBJID secondary , float priority , float scale , bool serialize ) {
SendPlayFXEffect ( entity - > GetObjectID ( ) , effectID , effectType , name , secondary , priority , scale , serialize ) ;
}
void GameMessages : : SendPlayFXEffect ( const LWOOBJID & entity , int32_t effectID , const std : : u16string & effectType , const std : : string & name , LWOOBJID secondary , float priority , float scale , bool serialize ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( entity ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PLAY_FX_EFFECT ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( effectID ! = - 1 ) ;
if ( effectID ! = - 1 ) bitStream . Write ( effectID ) ;
bitStream . Write < uint32_t > ( effectType . size ( ) ) ;
for ( const auto & k : effectType ) {
bitStream . Write < uint16_t > ( k ) ;
}
bitStream . Write ( scale ! = 1.0f ) ;
if ( scale ! = 1.0f ) bitStream . Write ( scale ) ;
bitStream . Write < uint32_t > ( name . size ( ) ) ;
for ( const auto & k : name ) {
bitStream . Write ( k ) ;
}
bitStream . Write ( priority ! = 1.0 ) ;
if ( priority ! = 1.0 ) bitStream . Write ( priority ) ;
bitStream . Write ( secondary ! = LWOOBJID_EMPTY ) ;
if ( secondary ! = LWOOBJID_EMPTY ) bitStream . Write ( secondary ) ;
bitStream . Write ( serialize ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET_BROADCAST ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendStopFXEffect ( Entity * entity , bool killImmediate , std : : string name ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : STOP_FX_EFFECT ) ;
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
bitStream . Write ( killImmediate ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write < uint32_t > ( name . size ( ) ) ;
bitStream . Write ( name . c_str ( ) , name . size ( ) ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET_BROADCAST ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendBroadcastTextToChatbox ( Entity * entity , const SystemAddress & sysAddr , const std : : u16string & attrs , const std : : u16string & wsText ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : BROADCAST_TEXT_TO_CHATBOX ) ;
2021-12-05 17:54:36 +00:00
LWONameValue attribs ;
attribs . name = attrs ;
attribs . length = attrs . size ( ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( attribs . length ) ;
2021-12-05 17:54:36 +00:00
for ( uint32_t i = 0 ; i < attribs . length ; + + i ) {
2023-12-24 00:11:00 +00:00
bitStream . Write < uint16_t > ( attribs . name [ i ] ) ;
2021-12-05 17:54:36 +00:00
}
2023-12-24 00:11:00 +00:00
bitStream . Write < uint16_t > ( 0x00 ) ; // Null Terminator
2021-12-05 17:54:36 +00:00
uint32_t wsTextLength = wsText . size ( ) ;
bitStream . Write ( wsTextLength ) ;
for ( uint32_t k = 0 ; k < wsTextLength ; k + + ) {
2023-12-24 00:11:00 +00:00
bitStream . Write < uint16_t > ( wsText [ k ] ) ;
2021-12-05 17:54:36 +00:00
}
2022-08-05 13:40:12 +00:00
SEND_PACKET_BROADCAST ;
2021-12-05 17:54:36 +00:00
}
2022-01-04 06:37:40 +00:00
void GameMessages : : SendSetCurrency ( Entity * entity , int64_t currency , int lootType , const LWOOBJID & sourceID , const LOT & sourceLOT , int sourceTradeID , bool overrideCurrent , eLootSourceType sourceType ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_CURRENCY ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( currency ) ;
bitStream . Write ( lootType ! = LOOTTYPE_NONE ) ;
if ( lootType ! = LOOTTYPE_NONE ) bitStream . Write ( lootType ) ;
2024-01-29 07:53:12 +00:00
bitStream . Write ( NiPoint3Constant : : ZERO ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( sourceLOT ! = LOT_NULL ) ;
if ( sourceLOT ! = LOT_NULL ) bitStream . Write ( sourceLOT ) ;
bitStream . Write ( sourceID ! = LWOOBJID_EMPTY ) ;
if ( sourceID ! = LWOOBJID_EMPTY ) bitStream . Write ( sourceID ) ;
bitStream . Write ( sourceTradeID ! = LWOOBJID_EMPTY ) ;
if ( sourceTradeID ! = LWOOBJID_EMPTY ) bitStream . Write ( sourceTradeID ) ;
2023-05-02 22:39:21 +00:00
bitStream . Write ( sourceType ! = eLootSourceType : : NONE ) ;
if ( sourceType ! = eLootSourceType : : NONE ) bitStream . Write ( sourceType ) ;
2021-12-05 17:54:36 +00:00
SystemAddress sysAddr = entity - > GetSystemAddress ( ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2023-12-29 04:24:30 +00:00
void GameMessages : : SendQuickBuildNotifyState ( Entity * entity , eQuickBuildState prevState , eQuickBuildState state , const LWOOBJID & playerID ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : REBUILD_NOTIFY_STATE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( prevState ) ;
bitStream . Write ( state ) ;
bitStream . Write ( playerID ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET_BROADCAST ;
2021-12-05 17:54:36 +00:00
}
2023-12-29 04:24:30 +00:00
void GameMessages : : SendEnableQuickBuild ( Entity * entity , bool enable , bool fail , bool success , eQuickBuildFailReason failReason , float duration , const LWOOBJID & playerID ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : ENABLE_REBUILD ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( enable ) ;
bitStream . Write ( fail ) ;
bitStream . Write ( success ) ;
2023-05-02 22:39:21 +00:00
bitStream . Write ( failReason ! = eQuickBuildFailReason : : NOT_GIVEN ) ;
if ( failReason ! = eQuickBuildFailReason : : NOT_GIVEN ) bitStream . Write ( failReason ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( duration ) ;
bitStream . Write ( playerID ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET_BROADCAST ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendTerminateInteraction ( const LWOOBJID & objectID , eTerminateType type , const LWOOBJID & terminator ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : TERMINATE_INTERACTION ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( terminator ) ;
bitStream . Write ( type ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET_BROADCAST ;
2021-12-05 17:54:36 +00:00
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendDieNoImplCode ( Entity * entity , const LWOOBJID & killerID , const LWOOBJID & lootOwnerID , eKillType killType , std : : u16string deathType , float directionRelative_AngleY , float directionRelative_AngleXZ , float directionRelative_Force , bool bClientDeath , bool bSpawnLoot ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : DIE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bClientDeath ) ;
bitStream . Write ( bSpawnLoot ) ;
bitStream . Write ( deathType ) ;
bitStream . Write ( directionRelative_AngleXZ ) ;
bitStream . Write ( directionRelative_AngleY ) ;
bitStream . Write ( directionRelative_Force ) ;
bitStream . Write ( killType ! = eKillType : : VIOLENT ) ;
if ( killType ! = eKillType : : VIOLENT ) bitStream . Write ( killType ) ;
bitStream . Write ( killerID ) ;
bitStream . Write ( lootOwnerID ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET_BROADCAST ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendDie ( Entity * entity , const LWOOBJID & killerID , const LWOOBJID & lootOwnerID , bool bDieAccepted , eKillType killType , std : : u16string deathType , float directionRelative_AngleY , float directionRelative_AngleXZ , float directionRelative_Force , bool bClientDeath , bool bSpawnLoot , float coinSpawnTime ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : DIE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bClientDeath ) ;
bitStream . Write ( bSpawnLoot ) ;
//bitStream.Write(coinSpawnTime != -1.0f);
//if (coinSpawnTime != -1.0f) bitStream.Write(coinSpawnTime);
uint32_t deathTypeLength = deathType . size ( ) ;
bitStream . Write ( deathTypeLength ) ;
for ( uint32_t k = 0 ; k < deathTypeLength ; k + + ) {
2023-12-24 00:11:00 +00:00
bitStream . Write < uint16_t > ( deathType [ k ] ) ;
2021-12-05 17:54:36 +00:00
}
bitStream . Write ( directionRelative_AngleXZ ) ;
bitStream . Write ( directionRelative_AngleY ) ;
bitStream . Write ( directionRelative_Force ) ;
2023-05-02 22:39:21 +00:00
bitStream . Write ( killType ! = eKillType : : VIOLENT ) ;
if ( killType ! = eKillType : : VIOLENT ) bitStream . Write ( killType ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( killerID ) ;
bitStream . Write ( lootOwnerID ! = LWOOBJID_EMPTY ) ;
if ( lootOwnerID ! = LWOOBJID_EMPTY ) {
bitStream . Write ( lootOwnerID ) ;
}
SEND_PACKET_BROADCAST ;
}
void GameMessages : : SendSetInventorySize ( Entity * entity , int invType , int size ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_INVENTORY_SIZE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( invType ) ;
bitStream . Write ( size ) ;
SystemAddress sysAddr = entity - > GetSystemAddress ( ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendSetEmoteLockState ( Entity * entity , bool bLock , int emoteID ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_EMOTE_LOCK_STATE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bLock ) ;
bitStream . Write ( emoteID ) ;
SystemAddress sysAddr = entity - > GetSystemAddress ( ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2022-01-24 22:02:56 +00:00
void GameMessages : : SendSetJetPackMode ( Entity * entity , bool use , bool bypassChecks , bool doHover , int effectID , float airspeed , float maxAirspeed , float verticalVelocity , int warningEffectID ) {
/* historical jamesster jetpack values
2021-12-05 17:54:36 +00:00
if ( bIsJamessterPhysics ) {
fAirspeed = 75 ;
fMaxAirspeed = 75 ;
fVertVel = 15 ;
}
2022-01-24 22:02:56 +00:00
*/
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_JET_PACK_MODE ) ;
2021-12-05 17:54:36 +00:00
2022-01-24 22:02:56 +00:00
bitStream . Write ( bypassChecks ) ;
bitStream . Write ( doHover ) ;
bitStream . Write ( use ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( effectID ! = - 1 ) ;
if ( effectID ! = - 1 ) bitStream . Write ( effectID ) ;
2022-01-24 22:02:56 +00:00
bitStream . Write ( airspeed ! = 10 ) ;
if ( airspeed ! = 10 ) bitStream . Write ( airspeed ) ;
2021-12-05 17:54:36 +00:00
2022-01-24 22:02:56 +00:00
bitStream . Write ( maxAirspeed ! = 15 ) ;
if ( maxAirspeed ! = 15 ) bitStream . Write ( maxAirspeed ) ;
2021-12-05 17:54:36 +00:00
2022-01-24 22:02:56 +00:00
bitStream . Write ( verticalVelocity ! = 1 ) ;
if ( verticalVelocity ! = 1 ) bitStream . Write ( verticalVelocity ) ;
2021-12-05 17:54:36 +00:00
2022-01-24 22:02:56 +00:00
bitStream . Write ( warningEffectID ! = - 1 ) ;
if ( warningEffectID ! = - 1 ) bitStream . Write ( warningEffectID ) ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
SEND_PACKET_BROADCAST ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendResurrect ( Entity * entity ) {
2023-03-08 13:32:03 +00:00
// Restore the players health after the animation for respawning has finished.
// This is when the health appered back in live, not immediately upon requesting respawn
// Add a half second in case someone decides to cheat and move during the death animation
// and just make sure the client has time to be ready.
constexpr float respawnTime = 3.66700005531311f + 0.5f ;
entity - > AddCallbackTimer ( respawnTime , [ = ] ( ) {
auto * destroyableComponent = entity - > GetComponent < DestroyableComponent > ( ) ;
if ( destroyableComponent ! = nullptr & & entity - > GetLOT ( ) = = 1 ) {
auto * levelComponent = entity - > GetComponent < LevelProgressionComponent > ( ) ;
if ( levelComponent ) {
2023-05-03 06:31:50 +00:00
int32_t healthToRestore = levelComponent - > GetLevel ( ) > = 45 ? 8 : 4 ;
if ( healthToRestore > destroyableComponent - > GetMaxHealth ( ) ) healthToRestore = destroyableComponent - > GetMaxHealth ( ) ;
destroyableComponent - > SetHealth ( healthToRestore ) ;
int32_t imaginationToRestore = levelComponent - > GetLevel ( ) > = 45 ? 20 : 6 ;
if ( imaginationToRestore > destroyableComponent - > GetMaxImagination ( ) ) imaginationToRestore = destroyableComponent - > GetMaxImagination ( ) ;
destroyableComponent - > SetImagination ( imaginationToRestore ) ;
2023-03-08 13:32:03 +00:00
}
2021-12-05 17:54:36 +00:00
}
2024-12-11 03:10:54 +00:00
} ) ;
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bool bRezImmediately = false ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : RESURRECT ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bRezImmediately ) ;
SEND_PACKET_BROADCAST ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendStop2DAmbientSound ( Entity * entity , bool force , std : : string audioGUID , bool result ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : STOP2_D_AMBIENT_SOUND ) ;
2021-12-05 17:54:36 +00:00
uint32_t audioGUIDSize = audioGUID . size ( ) ;
bitStream . Write ( force ) ;
bitStream . Write ( audioGUIDSize ) ;
2022-07-28 13:39:57 +00:00
for ( uint32_t k = 0 ; k < audioGUIDSize ; k + + ) {
2023-12-24 00:11:00 +00:00
bitStream . Write < char > ( audioGUID [ k ] ) ;
2021-12-05 17:54:36 +00:00
}
bitStream . Write ( result ) ;
SystemAddress sysAddr = entity - > GetSystemAddress ( ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendPlay2DAmbientSound ( Entity * entity , std : : string audioGUID , bool result ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PLAY2_D_AMBIENT_SOUND ) ;
2021-12-05 17:54:36 +00:00
uint32_t audioGUIDSize = audioGUID . size ( ) ;
bitStream . Write ( audioGUIDSize ) ;
for ( uint32_t k = 0 ; k < audioGUIDSize ; k + + ) {
2023-12-24 00:11:00 +00:00
bitStream . Write < char > ( audioGUID [ k ] ) ;
2021-12-05 17:54:36 +00:00
}
bitStream . Write ( result ) ;
SystemAddress sysAddr = entity - > GetSystemAddress ( ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendSetNetworkScriptVar ( Entity * entity , const SystemAddress & sysAddr , std : : string data ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SCRIPT_NETWORK_VAR_UPDATE ) ;
2021-12-05 17:54:36 +00:00
2022-08-02 13:56:20 +00:00
// FIXME: this is a bad place to need to do a conversion because we have no clue whether data is utf8 or plain ascii
// an this has performance implications
2021-12-05 17:54:36 +00:00
const auto u16Data = GeneralUtils : : ASCIIToUTF16 ( data ) ;
uint32_t dataSize = static_cast < uint32_t > ( u16Data . size ( ) ) ;
bitStream . Write ( dataSize ) ;
for ( auto value : u16Data ) {
2023-12-24 00:11:00 +00:00
bitStream . Write < uint16_t > ( value ) ;
2021-12-05 17:54:36 +00:00
}
2023-12-24 00:11:00 +00:00
if ( dataSize > 0 ) bitStream . Write < uint16_t > ( 0 ) ;
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
void GameMessages : : SendDropClientLoot ( Entity * entity , const LWOOBJID & sourceID , LOT item , int currency , NiPoint3 spawnPos , int count ) {
2023-10-28 10:32:19 +00:00
if ( Game : : config - > GetValue ( " disable_drops " ) = = " 1 " | | ! entity ) {
2021-12-05 17:54:36 +00:00
return ;
}
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
bool bUsePosition = false ;
NiPoint3 finalPosition ;
LWOOBJID lootID = LWOOBJID_EMPTY ;
LWOOBJID owner = entity - > GetObjectID ( ) ;
if ( item ! = LOT_NULL & & item ! = 0 ) {
2024-01-05 12:31:22 +00:00
lootID = ObjectIDManager : : GenerateObjectID ( ) ;
2021-12-05 17:54:36 +00:00
Loot : : Info info ;
info . id = lootID ;
info . count = count ;
info . lot = item ;
entity - > AddLootItem ( info ) ;
}
2021-12-11 13:21:00 +00:00
if ( item = = LOT_NULL & & currency ! = 0 ) {
2021-12-11 13:57:15 +00:00
entity - > RegisterCoinDrop ( currency ) ;
2021-12-11 13:21:00 +00:00
}
2024-01-29 07:53:12 +00:00
if ( spawnPos ! = NiPoint3Constant : : ZERO ) {
2021-12-05 17:54:36 +00:00
bUsePosition = true ;
//Calculate where the loot will go:
uint16_t degree = GeneralUtils : : GenerateRandomNumber < uint16_t > ( 0 , 360 ) ;
double rad = degree * 3.14 / 180 ;
double sin_v = sin ( rad ) * 4.2 ;
double cos_v = cos ( rad ) * 4.2 ;
finalPosition = NiPoint3 ( static_cast < float > ( spawnPos . GetX ( ) + sin_v ) , spawnPos . GetY ( ) , static_cast < float > ( spawnPos . GetZ ( ) + cos_v ) ) ;
}
//Write data to packet & send:
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : DROP_CLIENT_LOOT ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bUsePosition ) ;
2024-01-29 07:53:12 +00:00
bitStream . Write ( finalPosition ! = NiPoint3Constant : : ZERO ) ;
if ( finalPosition ! = NiPoint3Constant : : ZERO ) bitStream . Write ( finalPosition ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( currency ) ;
bitStream . Write ( item ) ;
bitStream . Write ( lootID ) ;
bitStream . Write ( owner ) ;
bitStream . Write ( sourceID ) ;
2024-01-29 07:53:12 +00:00
bitStream . Write ( spawnPos ! = NiPoint3Constant : : ZERO ) ;
if ( spawnPos ! = NiPoint3Constant : : ZERO ) bitStream . Write ( spawnPos ) ;
2021-12-05 17:54:36 +00:00
auto * team = TeamManager : : Instance ( ) - > GetTeam ( owner ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
// Currency and powerups should not sync
2022-07-28 13:39:57 +00:00
if ( team ! = nullptr & & currency = = 0 ) {
2024-02-09 05:40:43 +00:00
CDObjectsTable * objectsTable = CDClientManager : : GetTable < CDObjectsTable > ( ) ;
2021-12-05 17:54:36 +00:00
const CDObjects & object = objectsTable - > GetByID ( item ) ;
2022-07-28 13:39:57 +00:00
if ( object . type ! = " Powerup " ) {
for ( const auto memberId : team - > members ) {
2023-07-15 20:56:33 +00:00
auto * member = Game : : entityManager - > GetEntity ( memberId ) ;
2021-12-05 17:54:36 +00:00
if ( member = = nullptr ) continue ;
SystemAddress sysAddr = member - > GetSystemAddress ( ) ;
SEND_PACKET ;
}
return ;
}
}
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
SystemAddress sysAddr = entity - > GetSystemAddress ( ) ;
SEND_PACKET ;
}
2023-05-02 22:39:21 +00:00
void GameMessages : : SendSetPlayerControlScheme ( Entity * entity , eControlScheme controlScheme ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bool bDelayCamSwitchIfInCinematic = true ;
bool bSwitchCam = true ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_PLAYER_CONTROL_SCHEME ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bDelayCamSwitchIfInCinematic ) ;
bitStream . Write ( bSwitchCam ) ;
2023-05-02 22:39:21 +00:00
bitStream . Write ( controlScheme ! = eControlScheme : : SCHEME_A ) ;
if ( controlScheme ! = eControlScheme : : SCHEME_A ) bitStream . Write ( controlScheme ) ;
2021-12-05 17:54:36 +00:00
SystemAddress sysAddr = entity - > GetSystemAddress ( ) ;
SEND_PACKET ;
}
void GameMessages : : SendPlayerReachedRespawnCheckpoint ( Entity * entity , const NiPoint3 & position , const NiQuaternion & rotation ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PLAYER_REACHED_RESPAWN_CHECKPOINT ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( position . x ) ;
bitStream . Write ( position . y ) ;
bitStream . Write ( position . z ) ;
2024-01-29 07:53:12 +00:00
const bool bIsNotIdentity = rotation ! = NiQuaternionConstant : : IDENTITY ;
2023-12-24 00:11:00 +00:00
bitStream . Write ( bIsNotIdentity ) ;
if ( bIsNotIdentity ) {
2023-11-26 22:30:39 +00:00
bitStream . Write ( rotation . w ) ;
bitStream . Write ( rotation . x ) ;
bitStream . Write ( rotation . y ) ;
bitStream . Write ( rotation . z ) ;
2021-12-05 17:54:36 +00:00
}
SystemAddress sysAddr = entity - > GetSystemAddress ( ) ;
SEND_PACKET ;
}
2023-10-09 20:18:51 +00:00
void GameMessages : : SendAddSkill ( Entity * entity , TSkillID skillID , BehaviorSlot slotID ) {
2021-12-05 17:54:36 +00:00
int AICombatWeight = 0 ;
bool bFromSkillSet = false ;
int castType = 0 ;
float fTimeSecs = - 1.0f ;
int iTimesCanCast = - 1 ;
bool temporary = true ;
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : ADD_SKILL ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( AICombatWeight ! = 0 ) ;
if ( AICombatWeight ! = 0 ) bitStream . Write ( AICombatWeight ) ;
bitStream . Write ( bFromSkillSet ) ;
bitStream . Write ( castType ! = 0 ) ;
if ( castType ! = 0 ) bitStream . Write ( castType ) ;
bitStream . Write ( fTimeSecs ! = - 1.0f ) ;
if ( fTimeSecs ! = - 1.0f ) bitStream . Write ( fTimeSecs ) ;
bitStream . Write ( iTimesCanCast ! = - 1 ) ;
if ( iTimesCanCast ! = - 1 ) bitStream . Write ( iTimesCanCast ) ;
bitStream . Write ( skillID ) ;
2023-10-09 20:18:51 +00:00
bitStream . Write ( slotID ! = BehaviorSlot : : Invalid ) ;
if ( slotID ! = BehaviorSlot : : Invalid ) bitStream . Write ( slotID ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( temporary ) ;
SystemAddress sysAddr = entity - > GetSystemAddress ( ) ;
SEND_PACKET ;
}
void GameMessages : : SendRemoveSkill ( Entity * entity , TSkillID skillID ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : REMOVE_SKILL ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( false ) ;
bitStream . Write ( skillID ) ;
SystemAddress sysAddr = entity - > GetSystemAddress ( ) ;
SEND_PACKET ;
}
void GameMessages : : SendFinishArrangingWithItem ( Entity * entity , const LWOOBJID & buildArea ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bool bFirstTime = true ;
2021-12-05 17:54:36 +00:00
const LWOOBJID & buildAreaID = buildArea ;
int newSourceBAG = 0 ;
const LWOOBJID & newSourceID = LWOOBJID_EMPTY ;
LOT newSourceLOT = LOT_NULL ;
int newSourceTYPE = 0 ;
const LWOOBJID & newTargetID = LWOOBJID_EMPTY ;
LOT newTargetLOT = LOT_NULL ;
int newTargetTYPE = 0 ;
NiPoint3 newTargetPOS = NiPoint3 ( ) ;
int oldItemBAG = 0 ;
const LWOOBJID & oldItemID = LWOOBJID_EMPTY ;
LOT oldItemLOT = LOT_NULL ;
int oldItemTYPE = 0 ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : FINISH_ARRANGING_WITH_ITEM ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( buildAreaID ! = LWOOBJID_EMPTY ) ;
if ( buildAreaID ! = LWOOBJID_EMPTY ) bitStream . Write ( buildAreaID ) ;
bitStream . Write ( newSourceBAG ) ;
bitStream . Write ( newSourceID ) ;
bitStream . Write ( newSourceLOT ) ;
bitStream . Write ( newSourceTYPE ) ;
bitStream . Write ( newTargetID ) ;
bitStream . Write ( newTargetLOT ) ;
bitStream . Write ( newTargetTYPE ) ;
bitStream . Write ( newTargetPOS ) ;
bitStream . Write ( oldItemBAG ) ;
bitStream . Write ( oldItemID ) ;
bitStream . Write ( oldItemLOT ) ;
bitStream . Write ( oldItemTYPE ) ;
SystemAddress sysAddr = entity - > GetSystemAddress ( ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendModularBuildEnd ( Entity * entity ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : MODULAR_BUILD_END ) ;
2021-12-05 17:54:36 +00:00
SystemAddress sysAddr = entity - > GetSystemAddress ( ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendVendorOpenWindow ( Entity * entity , const SystemAddress & sysAddr ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : VENDOR_OPEN_WINDOW ) ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2022-04-26 10:41:16 +00:00
void GameMessages : : SendVendorStatusUpdate ( Entity * entity , const SystemAddress & sysAddr , bool bUpdateOnly ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2023-03-04 07:16:37 +00:00
VendorComponent * vendor = static_cast < VendorComponent * > ( entity - > GetComponent ( eReplicaComponentType : : VENDOR ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! vendor ) return ;
2023-08-03 10:51:52 +00:00
auto vendorItems = vendor - > GetInventory ( ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : VENDOR_STATUS_UPDATE ) ;
2021-12-05 17:54:36 +00:00
2022-07-17 07:35:11 +00:00
bitStream . Write ( bUpdateOnly ) ;
2023-08-03 10:51:52 +00:00
bitStream . Write < uint32_t > ( vendorItems . size ( ) ) ;
2021-12-05 17:54:36 +00:00
2023-08-04 02:44:03 +00:00
2023-08-03 10:51:52 +00:00
for ( const auto & item : vendorItems ) {
bitStream . Write ( item . lot ) ;
bitStream . Write ( item . sortPriority ) ;
2021-12-05 17:54:36 +00:00
}
2023-08-03 10:51:52 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2024-02-25 07:47:05 +00:00
void GameMessages : : SendVendorTransactionResult ( Entity * entity , const SystemAddress & sysAddr , eVendorTransactionResult result ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : VENDOR_TRANSACTION_RESULT ) ;
2024-02-25 07:47:05 +00:00
bitStream . Write ( result ) ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendRemoveItemFromInventory ( Entity * entity , const SystemAddress & sysAddr , LWOOBJID objectID , LOT templateID , int inventoryType , uint32_t stackCount , uint32_t stackRemaining ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
// this is used for a lot more than just inventory trashing (trades, vendors, etc.) but for now since it's just used for that, that's all im going to implement
bool bConfirmed = true ;
2021-12-05 17:54:36 +00:00
bool bDeleteItem = true ;
bool bOutSuccess = false ;
int eInvType = inventoryType ;
int eLootTypeSource = LOOTTYPE_NONE ;
bool forceDeletion = true ;
LWOOBJID iLootTypeSource = LWOOBJID_EMPTY ;
LWOOBJID iObjID = objectID ;
LOT iObjTemplate = templateID ;
LWOOBJID iRequestingObjID = LWOOBJID_EMPTY ;
uint32_t iStackCount = stackCount ;
uint32_t iStackRemaining = stackRemaining ;
LWOOBJID iSubkey = LWOOBJID_EMPTY ;
LWOOBJID iTradeID = LWOOBJID_EMPTY ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : REMOVE_ITEM_FROM_INVENTORY ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bConfirmed ) ;
bitStream . Write ( bDeleteItem ) ;
bitStream . Write ( bOutSuccess ) ;
bitStream . Write1 ( ) ;
bitStream . Write ( eInvType ) ;
bitStream . Write1 ( ) ;
bitStream . Write ( eLootTypeSource ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( 0 ) ; //extra info
//bitStream.Write<uint16_t>(0); //extra info
2021-12-05 17:54:36 +00:00
bitStream . Write ( forceDeletion ) ;
bitStream . Write0 ( ) ;
bitStream . Write1 ( ) ;
bitStream . Write ( iObjID ) ;
bitStream . Write1 ( ) ;
bitStream . Write ( iObjTemplate ) ;
bitStream . Write0 ( ) ;
bitStream . Write1 ( ) ;
bitStream . Write ( iStackCount ) ;
bitStream . Write1 ( ) ;
bitStream . Write ( iStackRemaining ) ;
bitStream . Write0 ( ) ;
bitStream . Write0 ( ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendConsumeClientItem ( Entity * entity , bool bSuccess , LWOOBJID item ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : CONSUME_CLIENT_ITEM ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bSuccess ) ;
bitStream . Write ( item ) ;
SystemAddress sysAddr = entity - > GetSystemAddress ( ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendUseItemResult ( Entity * entity , LOT templateID , bool useItemResult ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : USE_ITEM_RESULT ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( templateID ) ;
bitStream . Write ( useItemResult ) ;
SystemAddress sysAddr = entity - > GetSystemAddress ( ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2023-05-02 22:39:21 +00:00
void GameMessages : : SendUseItemRequirementsResponse ( LWOOBJID objectID , const SystemAddress & sysAddr , eUseItemResponse itemResponse ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2022-06-18 05:19:28 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : USE_ITEM_REQUIREMENTS_RESPONSE ) ;
2022-06-18 05:19:28 +00:00
bitStream . Write ( itemResponse ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2022-06-18 05:19:28 +00:00
}
2021-12-05 17:54:36 +00:00
void GameMessages : : SendMoveInventoryBatch ( Entity * entity , uint32_t stackCount , int srcInv , int dstInv , const LWOOBJID & iObjID ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2023-03-04 07:16:37 +00:00
InventoryComponent * inv = static_cast < InventoryComponent * > ( entity - > GetComponent ( eReplicaComponentType : : INVENTORY ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! inv ) return ;
Item * itemStack = inv - > FindItemById ( iObjID ) ;
if ( ! itemStack ) return ;
bool bAllowPartial = false ;
bool bOutSuccess = false ;
uint32_t count = stackCount ;
int dstBag = dstInv ;
LOT moveLOT = itemStack - > GetLot ( ) ;
//LWOOBJID moveSubkey = LWOOBJID_EMPTY;
bool showFlyingLoot = false ;
int srcBag = srcInv ;
LWOOBJID startObjectID = iObjID ;
bitStream . Write ( bAllowPartial ) ;
bitStream . Write ( bOutSuccess ) ;
if ( count = = 1 ) {
bitStream . Write0 ( ) ;
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
bitStream . Write1 ( ) ;
bitStream . Write ( count ) ;
}
if ( dstBag = = 0 ) {
bitStream . Write0 ( ) ;
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
bitStream . Write1 ( ) ;
bitStream . Write ( dstBag ) ;
}
bitStream . Write0 ( ) ;
bitStream . Write ( showFlyingLoot ) ;
if ( srcBag = = 0 ) {
bitStream . Write0 ( ) ;
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
bitStream . Write1 ( ) ;
bitStream . Write ( srcBag ) ;
}
bitStream . Write1 ( ) ;
bitStream . Write ( startObjectID ) ;
auto sysAddr = entity - > GetSystemAddress ( ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendMatchResponse ( Entity * entity , const SystemAddress & sysAddr , int response ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : MATCH_RESPONSE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( response ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2023-05-02 22:39:21 +00:00
void GameMessages : : SendMatchUpdate ( Entity * entity , const SystemAddress & sysAddr , std : : string data , eMatchUpdate type ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : MATCH_UPDATE ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( data . size ( ) ) ;
2021-12-05 17:54:36 +00:00
for ( char character : data ) {
2023-12-24 00:11:00 +00:00
bitStream . Write < uint16_t > ( character ) ;
2021-12-05 17:54:36 +00:00
}
2023-12-24 00:11:00 +00:00
if ( data . size ( ) > 0 ) bitStream . Write < uint16_t > ( 0 ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( type ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendRequestActivitySummaryLeaderboardData ( const LWOOBJID & objectID , const LWOOBJID & targetID ,
2022-07-28 13:39:57 +00:00
const SystemAddress & sysAddr , const int32_t & gameID ,
const int32_t & queryType , const int32_t & resultsEnd ,
const int32_t & resultsStart , bool weekly ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : REQUEST_ACTIVITY_SUMMARY_LEADERBOARD_DATA ) ;
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
bitStream . Write ( gameID ! = 0 ) ;
if ( gameID ! = 0 ) {
bitStream . Write < int32_t > ( gameID ) ;
}
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
bitStream . Write ( queryType ! = 1 ) ;
if ( queryType ! = 1 ) {
bitStream . Write < int32_t > ( queryType ) ;
}
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
bitStream . Write ( resultsEnd ! = 10 ) ;
if ( resultsEnd ! = 10 ) {
bitStream . Write < int32_t > ( resultsEnd ) ;
}
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
bitStream . Write ( resultsStart ! = 0 ) ;
if ( resultsStart ! = 0 ) {
bitStream . Write < int32_t > ( resultsStart ) ;
}
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
bitStream . Write < LWOOBJID > ( targetID ) ;
bitStream . Write ( weekly ) ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendActivityPause ( LWOOBJID objectId , bool pause , const SystemAddress & sysAddr ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : ACTIVITY_PAUSE ) ;
2022-07-23 02:58:20 +00:00
bitStream . Write ( pause ) ;
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendStartActivityTime ( LWOOBJID objectId , float_t startTime , const SystemAddress & sysAddr ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : START_ACTIVITY_TIME ) ;
2022-07-23 02:58:20 +00:00
bitStream . Write < float_t > ( startTime ) ;
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendRequestActivityEnter ( LWOOBJID objectId , const SystemAddress & sysAddr , bool bStart , LWOOBJID userID ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : REQUEST_ACTIVITY_ENTER ) ;
2022-07-23 02:58:20 +00:00
bitStream . Write < bool > ( bStart ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write < LWOOBJID > ( userID ) ;
2022-07-23 02:58:20 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2022-02-21 03:23:03 +00:00
void GameMessages : : NotifyLevelRewards ( LWOOBJID objectID , const SystemAddress & sysAddr , int level , bool sending_rewards ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2022-02-13 05:02:52 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : NOTIFY_LEVEL_REWARDS ) ;
2022-02-13 05:02:52 +00:00
bitStream . Write ( level ) ;
bitStream . Write ( sending_rewards ) ;
2022-07-17 07:35:11 +00:00
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2022-02-13 05:02:52 +00:00
}
2021-12-05 17:54:36 +00:00
void GameMessages : : SendSetShootingGalleryParams ( LWOOBJID objectId , const SystemAddress & sysAddr ,
2022-07-28 13:39:57 +00:00
float cameraFOV ,
float cooldown ,
float minDistance ,
NiPoint3 muzzlePosOffset ,
NiPoint3 playerPosOffset ,
float projectileVelocity ,
float timeLimit ,
bool bUseLeaderboards ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_SHOOTING_GALLERY_PARAMS ) ;
2021-12-05 17:54:36 +00:00
/*
bitStream . Write < float > ( cameraFOV ) ;
bitStream . Write < float > ( cooldown ) ;
bitStream . Write < float > ( minDistance ) ;
bitStream . Write < NiPoint3 > ( muzzlePosOffset ) ;
bitStream . Write < NiPoint3 > ( playerPosOffset ) ;
bitStream . Write < float > ( projectileVelocity ) ;
bitStream . Write < float > ( timeLimit ) ;
bitStream . Write < bool > ( bUseLeaderboards ) ;
*/
// No clue about the order here
bitStream . Write < NiPoint3 > ( playerPosOffset ) ;
bitStream . Write < float > ( projectileVelocity ) ;
bitStream . Write < float > ( cooldown ) ;
bitStream . Write < NiPoint3 > ( muzzlePosOffset ) ;
bitStream . Write < float > ( minDistance ) ;
bitStream . Write < float > ( cameraFOV ) ;
bitStream . Write < bool > ( bUseLeaderboards ) ;
bitStream . Write < float > ( timeLimit ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendNotifyClientShootingGalleryScore ( LWOOBJID objectId , const SystemAddress & sysAddr ,
2022-07-28 13:39:57 +00:00
float addTime ,
int32_t score ,
LWOOBJID target ,
NiPoint3 targetPos ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : NOTIFY_CLIENT_SHOOTING_GALLERY_SCORE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write < float > ( addTime ) ;
bitStream . Write < int32_t > ( score ) ;
bitStream . Write < LWOOBJID > ( target ) ;
bitStream . Write < NiPoint3 > ( targetPos ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleUpdateShootingGalleryRotation ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
float angle = 0.0f ;
2024-01-29 07:53:12 +00:00
NiPoint3 facing = NiPoint3Constant : : ZERO ;
NiPoint3 muzzlePos = NiPoint3Constant : : ZERO ;
2024-02-26 14:17:22 +00:00
inStream . Read ( angle ) ;
inStream . Read ( facing ) ;
inStream . Read ( muzzlePos ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleActivitySummaryLeaderboardData ( RakNet : : BitStream & inStream , Entity * entity ,
2022-07-28 13:39:57 +00:00
const SystemAddress & sysAddr ) {
2023-10-21 23:31:55 +00:00
LOG ( " We got mail! " ) ;
2021-12-05 17:54:36 +00:00
}
2023-05-30 11:23:48 +00:00
void GameMessages : : SendActivitySummaryLeaderboardData ( const LWOOBJID & objectID , const Leaderboard * leaderboard , const SystemAddress & sysAddr ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SEND_ACTIVITY_SUMMARY_LEADERBOARD_DATA ) ;
2021-12-05 17:54:36 +00:00
2024-02-27 05:25:45 +00:00
leaderboard - > Serialize ( bitStream ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleRequestActivitySummaryLeaderboardData ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2022-07-23 02:58:20 +00:00
int32_t gameID = 0 ;
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) inStream . Read ( gameID ) ;
2021-12-05 17:54:36 +00:00
2023-05-09 02:59:10 +00:00
Leaderboard : : InfoType queryType = Leaderboard : : InfoType : : MyStanding ;
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) inStream . Read < Leaderboard : : InfoType > ( queryType ) ;
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
int32_t resultsEnd = 10 ;
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) inStream . Read ( resultsEnd ) ;
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
int32_t resultsStart = 0 ;
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) inStream . Read ( resultsStart ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
LWOOBJID target { } ;
2024-02-26 14:17:22 +00:00
inStream . Read ( target ) ;
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
bool weekly = inStream . ReadBit ( ) ;
2021-12-05 17:54:36 +00:00
2024-12-06 11:03:47 +00:00
LeaderboardManager : : SendLeaderboard ( gameID , queryType , weekly , entity - > GetObjectID ( ) , entity - > GetObjectID ( ) ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleActivityStateChangeRequest ( RakNet : : BitStream & inStream , Entity * entity ) {
2022-07-23 02:58:20 +00:00
LWOOBJID objectID ;
2024-02-26 14:17:22 +00:00
inStream . Read < LWOOBJID > ( objectID ) ;
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
int32_t value1 ;
2024-02-26 14:17:22 +00:00
inStream . Read < int32_t > ( value1 ) ;
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
int32_t value2 ;
2024-02-26 14:17:22 +00:00
inStream . Read < int32_t > ( value2 ) ;
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
uint32_t stringValueLength ;
2024-02-26 14:17:22 +00:00
inStream . Read < uint32_t > ( stringValueLength ) ;
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
std : : u16string stringValue ;
for ( uint32_t i = 0 ; i < stringValueLength ; + + i ) {
uint16_t character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2022-07-23 02:58:20 +00:00
stringValue . push_back ( character ) ;
}
2021-12-05 17:54:36 +00:00
2023-07-15 20:56:33 +00:00
auto * assosiate = Game : : entityManager - > GetEntity ( objectID ) ;
2021-12-05 17:54:36 +00:00
2023-10-21 23:31:55 +00:00
LOG ( " %s [%i, %i] from %i to %i " , GeneralUtils : : UTF16ToWTF8 ( stringValue ) . c_str ( ) , value1 , value2 , entity - > GetLOT ( ) , assosiate ! = nullptr ? assosiate - > GetLOT ( ) : 0 ) ;
2021-12-05 17:54:36 +00:00
2023-07-15 20:56:33 +00:00
std : : vector < Entity * > scriptedActs = Game : : entityManager - > GetEntitiesByComponent ( eReplicaComponentType : : SHOOTING_GALLERY ) ;
2021-12-05 17:54:36 +00:00
for ( Entity * scriptEntity : scriptedActs ) {
scriptEntity - > OnActivityStateChangeRequest ( objectID , value1 , value2 , stringValue ) ;
}
2022-07-23 02:58:20 +00:00
entity - > OnActivityStateChangeRequest ( objectID , value1 , value2 , stringValue ) ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendStartCelebrationEffect ( Entity * entity , const SystemAddress & sysAddr , int celebrationID ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : START_CELEBRATION_EFFECT ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write < uint32_t > ( 0 ) ; //animation
bitStream . Write0 ( ) ; //No custom bg obj
bitStream . Write0 ( ) ; //custom path
bitStream . Write0 ( ) ; //leadin
bitStream . Write0 ( ) ; //leadout
bitStream . Write1 ( ) ;
bitStream . Write ( celebrationID ) ;
bitStream . Write < float > ( 0.0f ) ; //duration
bitStream . Write < uint32_t > ( 0 ) ; //icon
bitStream . Write < uint32_t > ( 0 ) ; //text
bitStream . Write < uint32_t > ( 0 ) ; //mixer
bitStream . Write < uint32_t > ( 0 ) ; //cue
bitStream . Write < uint32_t > ( 0 ) ; //pathnodename
bitStream . Write < uint32_t > ( 0 ) ; //soundguid
bitStream . Write < uint32_t > ( 0 ) ; //subtext
SEND_PACKET ;
}
void GameMessages : : SendSetRailMovement ( const LWOOBJID & objectID , bool pathGoForward , std : : u16string pathName ,
2022-07-28 13:39:57 +00:00
uint32_t pathStart , const SystemAddress & sysAddr , int32_t railActivatorComponentID ,
LWOOBJID railActivatorObjectID ) {
2022-07-23 02:58:20 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_RAIL_MOVEMENT ) ;
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
bitStream . Write ( pathGoForward ) ;
2021-12-05 17:54:36 +00:00
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( pathName . size ( ) ) ;
2022-07-23 02:58:20 +00:00
for ( auto character : pathName ) {
bitStream . Write < uint16_t > ( character ) ;
}
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
bitStream . Write < uint32_t > ( pathStart ) ;
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
const auto componentIDIsDefault = railActivatorComponentID = = - 1 ;
bitStream . Write ( ! componentIDIsDefault ) ;
if ( ! componentIDIsDefault )
bitStream . Write < int32_t > ( railActivatorComponentID ) ;
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
const auto activatorObjectIDIsDefault = railActivatorObjectID = = LWOOBJID_EMPTY ;
bitStream . Write ( ! activatorObjectIDIsDefault ) ;
if ( ! activatorObjectIDIsDefault )
bitStream . Write < LWOOBJID > ( railActivatorObjectID ) ;
2021-12-05 17:54:36 +00:00
2022-07-23 02:58:20 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendStartRailMovement ( const LWOOBJID & objectID , std : : u16string pathName , std : : u16string startSound ,
std : : u16string loopSound , std : : u16string stopSound , const SystemAddress & sysAddr ,
uint32_t pathStart , bool goForward , bool damageImmune , bool noAggro , bool notifyActor ,
bool showNameBillboard , bool cameraLocked , bool collisionEnabled , bool useDB ,
int32_t railComponentID , LWOOBJID railActivatorObjectID ) {
2022-07-23 02:58:20 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : START_RAIL_MOVEMENT ) ;
2022-07-23 02:58:20 +00:00
bitStream . Write ( damageImmune ) ;
bitStream . Write ( noAggro ) ;
bitStream . Write ( notifyActor ) ;
bitStream . Write ( showNameBillboard ) ;
bitStream . Write ( cameraLocked ) ;
bitStream . Write ( collisionEnabled ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( loopSound . size ( ) ) ;
2022-07-23 02:58:20 +00:00
for ( auto character : loopSound ) {
bitStream . Write < uint16_t > ( character ) ;
}
bitStream . Write ( goForward ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( pathName . size ( ) ) ;
2022-07-23 02:58:20 +00:00
for ( auto character : pathName ) {
bitStream . Write < uint16_t > ( character ) ;
}
const auto pathStartIsDefault = pathStart = = 0 ;
bitStream . Write ( ! pathStartIsDefault ) ;
if ( ! pathStartIsDefault ) {
bitStream . Write < uint32_t > ( pathStart ) ;
}
const auto railComponentIDIsDefault = railComponentID = = - 1 ;
bitStream . Write ( ! railComponentIDIsDefault ) ;
if ( ! railComponentIDIsDefault ) {
bitStream . Write < int32_t > ( railComponentID ) ;
}
const auto railObjectIDIsDefault = railActivatorObjectID = = LWOOBJID_EMPTY ;
bitStream . Write ( ! railObjectIDIsDefault ) ;
if ( ! railObjectIDIsDefault ) {
bitStream . Write < LWOOBJID > ( railActivatorObjectID ) ;
}
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( startSound . size ( ) ) ;
2022-07-23 02:58:20 +00:00
for ( auto character : startSound ) {
bitStream . Write < uint16_t > ( character ) ;
}
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( stopSound . size ( ) ) ;
2022-07-23 02:58:20 +00:00
for ( auto character : stopSound ) {
bitStream . Write < uint16_t > ( character ) ;
}
bitStream . Write ( useDB ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
2021-12-05 17:54:36 +00:00
}
void GameMessages : : SendNotifyClientObject ( const LWOOBJID & objectID , std : : u16string name , int param1 , int param2 , const LWOOBJID & paramObj , std : : string paramStr , const SystemAddress & sysAddr ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : NOTIFY_CLIENT_OBJECT ) ;
2021-12-05 17:54:36 +00:00
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( name . size ( ) ) ;
2021-12-05 17:54:36 +00:00
for ( auto character : name ) {
bitStream . Write < uint16_t > ( character ) ;
}
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
bitStream . Write ( param1 ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
bitStream . Write ( param2 ) ;
bitStream . Write ( paramObj ) ;
2022-07-17 07:35:11 +00:00
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( paramStr . size ( ) ) ;
2021-12-05 17:54:36 +00:00
for ( auto character : paramStr ) {
bitStream . Write ( character ) ;
}
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
void GameMessages : : SendNotifyClientZoneObject ( const LWOOBJID & objectID , const std : : u16string & name , int param1 ,
2022-07-28 13:39:57 +00:00
int param2 , const LWOOBJID & paramObj , const std : : string & paramStr ,
const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : NOTIFY_CLIENT_ZONE_OBJECT ) ;
2021-12-05 17:54:36 +00:00
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( name . size ( ) ) ;
2021-12-05 17:54:36 +00:00
for ( const auto & character : name ) {
bitStream . Write < uint16_t > ( character ) ;
}
bitStream . Write ( param1 ) ;
bitStream . Write ( param2 ) ;
bitStream . Write ( paramObj ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( paramStr . size ( ) ) ;
2021-12-05 17:54:36 +00:00
for ( const auto & character : paramStr ) {
bitStream . Write ( character ) ;
}
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
void GameMessages : : SendNotifyClientFailedPrecondition ( LWOOBJID objectId , const SystemAddress & sysAddr ,
2022-07-28 13:39:57 +00:00
const std : : u16string & failedReason , int preconditionID ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : NOTIFY_CLIENT_FAILED_PRECONDITION ) ;
2021-12-05 17:54:36 +00:00
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( failedReason . size ( ) ) ;
2021-12-05 17:54:36 +00:00
for ( uint16_t character : failedReason ) {
2023-12-24 00:11:00 +00:00
bitStream . Write < uint16_t > ( character ) ;
2021-12-05 17:54:36 +00:00
}
bitStream . Write ( preconditionID ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendToggleGMInvis ( LWOOBJID objectId , bool enabled , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : TOGGLE_GM_INVIS ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( enabled ) ; // does not matter?
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendSetName ( LWOOBJID objectID , std : : u16string name , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_NAME ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write < uint32_t > ( name . size ( ) ) ;
for ( size_t i = 0 ; i < name . size ( ) ; + + i )
bitStream . Write ( name [ i ] ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
void GameMessages : : SendBBBSaveResponse ( const LWOOBJID & objectId , const LWOOBJID & localID , unsigned char * buffer , uint32_t bufferSize , const SystemAddress & sysAddr ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : BBB_SAVE_RESPONSE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( localID ) ;
//Write a fake sd0 header:
bitStream . Write < unsigned char > ( 0x73 ) ; //s
bitStream . Write < unsigned char > ( 0x64 ) ; //d
bitStream . Write < unsigned char > ( 0x30 ) ; //0
bitStream . Write < unsigned char > ( 0x01 ) ; //1
bitStream . Write < unsigned char > ( 0xFF ) ; //end magic
bitStream . Write ( bufferSize ) ;
for ( size_t i = 0 ; i < bufferSize ; + + i )
bitStream . Write ( buffer [ i ] ) ;
SEND_PACKET ;
}
// Property
2022-07-28 13:39:57 +00:00
void GameMessages : : SendOpenPropertyVendor ( const LWOOBJID objectId , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : OPEN_PROPERTY_VENDOR ) ;
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendOpenPropertyManagment ( const LWOOBJID objectId , const SystemAddress & sysAddr ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2021-12-05 17:54:36 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( PropertyManagementComponent : : Instance ( ) - > GetParent ( ) - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : OPEN_PROPERTY_MANAGEMENT ) ;
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendDownloadPropertyData ( const LWOOBJID objectId , const PropertyDataMessage & data , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : DOWNLOAD_PROPERTY_DATA ) ;
2021-12-05 17:54:36 +00:00
data . Serialize ( bitStream ) ;
2023-10-21 23:31:55 +00:00
LOG ( " (%llu) sending property data (%d) " , objectId , sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendPropertyRentalResponse ( const LWOOBJID objectId , const LWOCLONEID cloneId , const uint32_t code , const LWOOBJID propertyId , const int64_t rentDue , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PROPERTY_RENTAL_RESPONSE ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
bitStream . Write ( cloneId ) ;
bitStream . Write ( code ) ;
bitStream . Write ( propertyId ) ;
bitStream . Write ( rentDue ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
void GameMessages : : SendLockNodeRotation ( Entity * entity , std : : string nodeName ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : LOCK_NODE_ROTATION ) ;
2021-12-05 17:54:36 +00:00
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( nodeName . size ( ) ) ;
2021-12-05 17:54:36 +00:00
for ( char character : nodeName ) {
bitStream . Write ( character ) ;
}
SEND_PACKET_BROADCAST ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendSetBuildModeConfirmed ( LWOOBJID objectId , const SystemAddress & sysAddr , bool start , bool warnVisitors , bool modePaused , int32_t modeValue , LWOOBJID playerId , NiPoint3 startPos ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_BUILD_MODE_CONFIRMED ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( start ) ;
bitStream . Write ( warnVisitors ) ;
bitStream . Write ( modePaused ) ;
bitStream . Write1 ( ) ;
bitStream . Write ( modeValue ) ;
bitStream . Write ( playerId ) ;
bitStream . Write1 ( ) ;
bitStream . Write ( startPos ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendGetModelsOnProperty ( LWOOBJID objectId , std : : map < LWOOBJID , LWOOBJID > models , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : GET_MODELS_ON_PROPERTY ) ;
2021-12-05 17:54:36 +00:00
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( models . size ( ) ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
for ( const auto & pair : models ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( pair . first ) ;
bitStream . Write ( pair . second ) ;
}
2023-10-21 23:31:55 +00:00
LOG ( " Sending property models to (%llu) (%d) " , objectId , sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) ;
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendZonePropertyModelEquipped ( LWOOBJID objectId , LWOOBJID playerId , LWOOBJID propertyId , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : ZONE_PROPERTY_MODEL_EQUIPPED ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( playerId ) ;
bitStream . Write ( propertyId ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
void GameMessages : : SendPlaceModelResponse ( LWOOBJID objectId , const SystemAddress & sysAddr , NiPoint3 position ,
2022-07-28 13:39:57 +00:00
LWOOBJID plaque , int32_t response , NiQuaternion rotation ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PLACE_MODEL_RESPONSE ) ;
2021-12-05 17:54:36 +00:00
2024-01-29 07:53:12 +00:00
bitStream . Write ( position ! = NiPoint3Constant : : ZERO ) ;
if ( position ! = NiPoint3Constant : : ZERO ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( position ) ;
}
bitStream . Write ( plaque ! = LWOOBJID_EMPTY ) ;
2022-07-28 13:39:57 +00:00
if ( plaque ! = LWOOBJID_EMPTY ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( plaque ) ;
}
bitStream . Write ( response ! = 0 ) ;
2022-07-28 13:39:57 +00:00
if ( response ! = 0 ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( response ) ;
}
2024-01-29 07:53:12 +00:00
bitStream . Write ( rotation ! = NiQuaternionConstant : : IDENTITY ) ;
if ( rotation ! = NiQuaternionConstant : : IDENTITY ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( response ) ;
}
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendUGCEquipPreCreateBasedOnEditMode ( LWOOBJID objectId , const SystemAddress & sysAddr , int modelCount , LWOOBJID model ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : HANDLE_UGC_POST_CREATE_BASED_ON_EDIT_MODE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( modelCount ) ;
bitStream . Write ( model ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendUGCEquipPostDeleteBasedOnEditMode ( LWOOBJID objectId , const SystemAddress & sysAddr , LWOOBJID inventoryItem , int itemTotal ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : HANDLE_UGC_POST_DELETE_BASED_ON_EDIT_MODE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( inventoryItem ) ;
bitStream . Write ( itemTotal ! = 0 ) ;
2022-07-28 13:39:57 +00:00
if ( itemTotal ! = 0 ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( itemTotal ) ;
}
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleSetPropertyAccess ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
uint8_t accessType { } ;
int32_t renew { } ;
bool accessTypeIsDefault { } ;
2024-02-26 14:17:22 +00:00
inStream . Read ( accessTypeIsDefault ) ;
if ( accessTypeIsDefault ! = 0 ) inStream . Read ( accessType ) ;
2021-12-05 17:54:36 +00:00
bool renewIsDefault { } ;
2024-02-26 14:17:22 +00:00
inStream . Read ( renewIsDefault ) ;
if ( renewIsDefault ! = 0 ) inStream . Read ( renew ) ;
2021-12-05 17:54:36 +00:00
2023-10-21 23:31:55 +00:00
LOG ( " Set privacy option to: %i " , accessType ) ;
2021-12-05 17:54:36 +00:00
if ( PropertyManagementComponent : : Instance ( ) = = nullptr ) return ;
PropertyManagementComponent : : Instance ( ) - > SetPrivacyOption ( static_cast < PropertyPrivacyOption > ( accessType ) ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleUnUseModel ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2022-11-28 00:48:46 +00:00
bool unknown { } ;
LWOOBJID objIdToAddToInventory { } ;
2024-02-26 14:17:22 +00:00
inStream . Read ( unknown ) ;
inStream . Read ( objIdToAddToInventory ) ;
2022-11-28 00:48:46 +00:00
auto * inventoryComponent = entity - > GetComponent < InventoryComponent > ( ) ;
if ( inventoryComponent ) {
auto * inventory = inventoryComponent - > GetInventory ( eInventoryType : : MODELS_IN_BBB ) ;
auto * item = inventory - > FindItemById ( objIdToAddToInventory ) ;
if ( item ) {
inventoryComponent - > MoveItemToInventory ( item , eInventoryType : : MODELS , 1 ) ;
} else {
2023-10-21 23:31:55 +00:00
LOG ( " item id %llu not found in MODELS_IN_BBB inventory, likely because it does not exist " , objIdToAddToInventory ) ;
2022-11-28 00:48:46 +00:00
}
}
if ( unknown ) {
CBITSTREAM ;
2024-11-18 00:39:44 +00:00
BitStreamUtils : : WriteHeader ( bitStream , eConnectionType : : CLIENT , MessageType : : Client : : BLUEPRINT_SAVE_RESPONSE ) ;
2022-11-28 00:48:46 +00:00
bitStream . Write < LWOOBJID > ( LWOOBJID_EMPTY ) ; //always zero so that a check on the client passes
bitStream . Write ( eBlueprintSaveResponseType : : PlacementFailed ) ; // Sending a non-zero error code here prevents the client from deleting its in progress build for some reason?
bitStream . Write < uint32_t > ( 0 ) ;
SEND_PACKET ;
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleUpdatePropertyOrModelForFilterCheck ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
bool isProperty { } ;
LWOOBJID objectId { } ;
LWOOBJID playerId { } ;
LWOOBJID worldId { } ;
uint32_t nameLength { } ;
std : : u16string name { } ;
uint32_t descriptionLength { } ;
std : : u16string description { } ;
2024-02-26 14:17:22 +00:00
inStream . Read ( isProperty ) ;
inStream . Read ( objectId ) ;
inStream . Read ( playerId ) ;
inStream . Read ( worldId ) ;
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
inStream . Read ( descriptionLength ) ;
2022-07-28 13:39:57 +00:00
for ( uint32_t i = 0 ; i < descriptionLength ; + + i ) {
2021-12-05 17:54:36 +00:00
uint16_t character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2021-12-05 17:54:36 +00:00
description . push_back ( character ) ;
}
2024-02-26 14:17:22 +00:00
inStream . Read ( nameLength ) ;
2022-07-28 13:39:57 +00:00
for ( uint32_t i = 0 ; i < nameLength ; + + i ) {
2021-12-05 17:54:36 +00:00
uint16_t character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2021-12-05 17:54:36 +00:00
name . push_back ( character ) ;
}
PropertyManagementComponent : : Instance ( ) - > UpdatePropertyDetails ( GeneralUtils : : UTF16ToWTF8 ( name ) , GeneralUtils : : UTF16ToWTF8 ( description ) ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleQueryPropertyData ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2023-10-21 23:31:55 +00:00
LOG ( " Entity (%i) requesting data " , entity - > GetLOT ( ) ) ;
2021-12-05 17:54:36 +00:00
/*
2023-07-15 20:56:33 +00:00
auto entites = Game : : entityManager - > GetEntitiesByComponent ( eReplicaComponentType : : PROPERTY_VENDOR ) ;
2021-12-05 17:54:36 +00:00
entity = entites [ 0 ] ;
*/
2023-03-04 07:16:37 +00:00
auto * propertyVendorComponent = static_cast < PropertyVendorComponent * > ( entity - > GetComponent ( eReplicaComponentType : : PROPERTY_VENDOR ) ) ;
2021-12-05 17:54:36 +00:00
if ( propertyVendorComponent ! = nullptr ) {
propertyVendorComponent - > OnQueryPropertyData ( entity , sysAddr ) ;
}
/*
2023-07-15 20:56:33 +00:00
entites = Game : : entityManager - > GetEntitiesByComponent ( eReplicaComponentType : : PROPERTY_MANAGEMENT ) ;
2021-12-05 17:54:36 +00:00
entity = entites [ 0 ] ;
*/
2023-03-04 07:16:37 +00:00
auto * propertyManagerComponent = static_cast < PropertyManagementComponent * > ( entity - > GetComponent ( eReplicaComponentType : : PROPERTY_MANAGEMENT ) ) ;
2021-12-05 17:54:36 +00:00
if ( propertyManagerComponent ! = nullptr ) {
propertyManagerComponent - > OnQueryPropertyData ( entity , sysAddr ) ;
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleSetBuildMode ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
bool start { } ;
int32_t distanceType = - 1 ;
bool modePaused { } ;
int modeValue = 1 ;
LWOOBJID playerId { } ;
2024-01-29 07:53:12 +00:00
NiPoint3 startPosition = NiPoint3Constant : : ZERO ;
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
inStream . Read ( start ) ;
2022-07-17 07:35:11 +00:00
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) )
inStream . Read ( distanceType ) ;
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
inStream . Read ( modePaused ) ;
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) )
inStream . Read ( modeValue ) ;
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
inStream . Read ( playerId ) ;
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) )
inStream . Read ( startPosition ) ;
2021-12-05 17:54:36 +00:00
2023-07-15 20:56:33 +00:00
auto * player = Game : : entityManager - > GetEntity ( playerId ) ;
2021-12-05 17:54:36 +00:00
2024-01-29 07:53:12 +00:00
if ( startPosition = = NiPoint3Constant : : ZERO ) {
2021-12-05 17:54:36 +00:00
startPosition = player - > GetPosition ( ) ;
}
player - > GetCharacter ( ) - > SetBuildMode ( start ) ;
2023-10-21 23:31:55 +00:00
LOG ( " Sending build mode confirm (%i): (%d) (%i) (%d) (%i) (%llu) " , entity - > GetLOT ( ) , start , distanceType , modePaused , modeValue , playerId ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
SendSetBuildModeConfirmed ( entity - > GetObjectID ( ) , UNASSIGNED_SYSTEM_ADDRESS , start , false , modePaused , modeValue , playerId , startPosition ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleStartBuildingWithItem ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2023-03-04 07:16:37 +00:00
if ( ! entity - > HasComponent ( eReplicaComponentType : : PROPERTY_MANAGEMENT ) ) {
2021-12-05 17:54:36 +00:00
return ;
}
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
bool firstTime { } ;
bool success { } ;
int32_t sourceBag { } ;
LWOOBJID sourceId { } ;
LOT sourceLot { } ;
int32_t sourceType { } ;
LWOOBJID targetId { } ;
LOT targetLot { } ;
NiPoint3 targetPosition { } ;
int32_t targetType { } ;
2024-02-26 14:17:22 +00:00
inStream . Read ( firstTime ) ;
inStream . Read ( success ) ;
inStream . Read ( sourceBag ) ;
inStream . Read ( sourceId ) ;
inStream . Read ( sourceLot ) ;
inStream . Read ( sourceType ) ;
inStream . Read ( targetId ) ;
inStream . Read ( targetLot ) ;
inStream . Read ( targetPosition ) ;
inStream . Read ( targetType ) ;
2021-12-05 17:54:36 +00:00
if ( sourceType = = 1 ) {
sourceType = 4 ;
}
2023-10-21 23:31:55 +00:00
LOG ( " Handling start building with item (%i): (%d) (%d) (%i) (%llu) (%i) (%i) (%llu) (%i) (%i) " , entity - > GetLOT ( ) , firstTime , success , sourceBag , sourceId , sourceLot , sourceType , targetId , targetLot , targetType ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
auto * user = UserManager : : Instance ( ) - > GetUser ( sysAddr ) ;
2023-07-15 20:56:33 +00:00
auto * player = Game : : entityManager - > GetEntity ( user - > GetLoggedInChar ( ) ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
SendStartArrangingWithItem (
player ,
sysAddr ,
firstTime ,
entity - > GetObjectID ( ) ,
player - > GetPosition ( ) ,
sourceBag ,
sourceId ,
sourceLot ,
sourceType ,
targetId ,
targetLot ,
targetPosition ,
targetType
) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandlePropertyEditorBegin ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
PropertyManagementComponent : : Instance ( ) - > OnStartBuilding ( ) ;
2022-07-17 07:35:11 +00:00
2023-07-17 22:55:33 +00:00
Game : : zoneManager - > GetZoneControlObject ( ) - > OnZonePropertyEditBegin ( ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandlePropertyEditorEnd ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
PropertyManagementComponent : : Instance ( ) - > OnFinishBuilding ( ) ;
2023-07-17 22:55:33 +00:00
Game : : zoneManager - > GetZoneControlObject ( ) - > OnZonePropertyEditEnd ( ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandlePropertyContentsFromClient ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
User * user = UserManager : : Instance ( ) - > GetUser ( sysAddr ) ;
2023-07-15 20:56:33 +00:00
Entity * player = Game : : entityManager - > GetEntity ( user - > GetLoggedInChar ( ) ) ;
2021-12-05 17:54:36 +00:00
SendGetModelsOnProperty ( player - > GetObjectID ( ) , PropertyManagementComponent : : Instance ( ) - > GetModels ( ) , UNASSIGNED_SYSTEM_ADDRESS ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandlePropertyModelEquipped ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2023-07-17 22:55:33 +00:00
Game : : zoneManager - > GetZoneControlObject ( ) - > OnZonePropertyModelEquipped ( ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandlePlacePropertyModel ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
LWOOBJID model ;
2024-02-26 14:17:22 +00:00
inStream . Read ( model ) ;
2022-07-17 07:35:11 +00:00
2024-01-29 07:53:12 +00:00
PropertyManagementComponent : : Instance ( ) - > UpdateModelPosition ( model , NiPoint3Constant : : ZERO , NiQuaternionConstant : : IDENTITY ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleUpdatePropertyModel ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
LWOOBJID model ;
NiPoint3 position ;
2024-01-29 07:53:12 +00:00
NiQuaternion rotation = NiQuaternionConstant : : IDENTITY ;
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
inStream . Read ( model ) ;
inStream . Read ( position ) ;
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) {
inStream . Read ( rotation ) ;
2021-12-05 17:54:36 +00:00
}
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
PropertyManagementComponent : : Instance ( ) - > UpdateModelPosition ( model , position , rotation ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleDeletePropertyModel ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
LWOOBJID model = LWOOBJID_EMPTY ;
int deleteReason = 0 ;
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) {
inStream . Read ( model ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) {
inStream . Read ( deleteReason ) ;
2021-12-05 17:54:36 +00:00
}
PropertyManagementComponent : : Instance ( ) - > DeleteModel ( model , deleteReason ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleBBBLoadItemRequest ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2022-11-28 00:48:46 +00:00
LWOOBJID previousItemID = LWOOBJID_EMPTY ;
2024-02-26 14:17:22 +00:00
inStream . Read ( previousItemID ) ;
2022-11-28 00:48:46 +00:00
2023-10-21 23:31:55 +00:00
LOG ( " Load item request for: %lld " , previousItemID ) ;
2022-11-28 00:48:46 +00:00
LWOOBJID newId = previousItemID ;
auto * inventoryComponent = entity - > GetComponent < InventoryComponent > ( ) ;
if ( inventoryComponent ) {
auto * inventory = inventoryComponent - > GetInventory ( eInventoryType : : MODELS ) ;
auto * itemToMove = inventory - > FindItemById ( previousItemID ) ;
if ( itemToMove ) {
LOT previousLot = itemToMove - > GetLot ( ) ;
inventoryComponent - > MoveItemToInventory ( itemToMove , eInventoryType : : MODELS_IN_BBB , 1 , false ) ;
auto * destinationInventory = inventoryComponent - > GetInventory ( eInventoryType : : MODELS_IN_BBB ) ;
if ( destinationInventory ) {
auto * movedItem = destinationInventory - > FindItemByLot ( previousLot ) ;
if ( movedItem ) newId = movedItem - > GetId ( ) ;
}
} else {
2023-10-21 23:31:55 +00:00
LOG ( " item id %llu not found in MODELS inventory, likely because it does not exist " , previousItemID ) ;
2022-11-28 00:48:46 +00:00
}
}
2021-12-05 17:54:36 +00:00
2022-11-28 00:48:46 +00:00
// Second argument always true (successful) for now
SendBlueprintLoadItemResponse ( sysAddr , true , previousItemID , newId ) ;
}
2021-12-05 17:54:36 +00:00
2022-11-28 00:48:46 +00:00
void GameMessages : : SendBlueprintLoadItemResponse ( const SystemAddress & sysAddr , bool success , LWOOBJID oldItemId , LWOOBJID newItemId ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
2024-11-18 00:39:44 +00:00
BitStreamUtils : : WriteHeader ( bitStream , eConnectionType : : CLIENT , MessageType : : Client : : BLUEPRINT_LOAD_RESPONSE_ITEMID ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint8_t > ( success ) ;
2022-11-28 00:48:46 +00:00
bitStream . Write < LWOOBJID > ( oldItemId ) ;
bitStream . Write < LWOOBJID > ( newItemId ) ;
2021-12-05 17:54:36 +00:00
SEND_PACKET ;
}
2022-07-20 08:28:57 +00:00
void GameMessages : : SendSmash ( Entity * entity , float force , float ghostOpacity , LWOOBJID killerID , bool ignoreObjectVisibility ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2022-07-20 08:28:57 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SMASH ) ;
2022-07-20 08:28:57 +00:00
bitStream . Write ( ignoreObjectVisibility ) ;
bitStream . Write ( force ) ;
bitStream . Write ( ghostOpacity ) ;
bitStream . Write ( killerID ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET_BROADCAST ;
2022-07-20 08:28:57 +00:00
}
void GameMessages : : SendUnSmash ( Entity * entity , LWOOBJID builderID , float duration ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
2022-07-20 08:28:57 +00:00
2022-08-05 13:40:12 +00:00
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : UN_SMASH ) ;
2022-07-20 08:28:57 +00:00
bitStream . Write ( builderID ! = LWOOBJID_EMPTY ) ;
if ( builderID ! = LWOOBJID_EMPTY ) bitStream . Write ( builderID ) ;
bitStream . Write ( duration ! = 3.0f ) ;
if ( duration ! = 3.0f ) bitStream . Write ( duration ) ;
2022-08-05 13:40:12 +00:00
SEND_PACKET_BROADCAST ;
2022-07-20 08:28:57 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleControlBehaviors ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2022-10-31 22:32:07 +00:00
AMFDeserialize reader ;
2024-11-19 02:45:24 +00:00
std : : unique_ptr < AMFArrayValue > amfArguments { static_cast < AMFArrayValue * > ( reader . Read ( inStream ) . release ( ) ) } ;
2023-05-13 22:22:00 +00:00
if ( amfArguments - > GetValueType ( ) ! = eAmf : : Array ) return ;
2022-10-31 22:32:07 +00:00
uint32_t commandLength { } ;
2024-02-26 14:17:22 +00:00
inStream . Read ( commandLength ) ;
2022-10-31 22:32:07 +00:00
std : : string command ;
2024-02-27 07:29:51 +00:00
command . reserve ( commandLength ) ;
for ( uint32_t i = 0 ; i < commandLength ; + + i ) {
2022-10-31 22:32:07 +00:00
unsigned char character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2022-10-31 22:32:07 +00:00
command . push_back ( character ) ;
}
2024-02-27 07:29:51 +00:00
auto * const owner = PropertyManagementComponent : : Instance ( ) - > GetOwner ( ) ;
2022-11-28 00:48:46 +00:00
if ( ! owner ) return ;
2022-10-31 22:32:07 +00:00
2024-02-27 07:29:51 +00:00
ControlBehaviors : : Instance ( ) . ProcessCommand ( entity , * amfArguments , command , owner ) ;
2022-07-20 08:28:57 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleBBBSaveRequest ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2022-10-29 08:12:29 +00:00
/*
___ ___
/ \ / \ ___ _ __ ___ / __ \ ___ / \ _ __ __ _ __ _ ___ _ __ ___
/ / _ / / _ \ ' __ / _ \ / __ \ /// _ \ / /\ / '__/ _` |/ _` |/ _ \| '_ \/ __|
/ __ / __ / | | __ / / \ / \ __ / / / _ / / | | | ( _ | | ( _ | | ( _ ) | | | \ __ \
\ / / _ / \ ___ | _ | \ ___ | \ _____ / \ ___ | / ___ , ' | _ | \ __ , _ | \ __ , | \ ___ / | _ | | _ | ___ /
| ___ /
___ _
/ __ \ _____ ____ _ _ __ ___ / \
/ __ \ /// _ \ \ /\ / / _` | '__/ _ \/ /
/ \ / \ __ / \ V V / ( _ | | | | __ / \ _ /
\ _____ / \ ___ | \ _ / \ _ / \ __ , _ | _ | \ ___ \ /
< > = = = = = = = ( )
( / \ ___ / | \ \ ( ) = = = = = = = = = = < > _
\ _ / | \ \ //|\ ______/ \)
\ _ | \ \ // | \_/
\ | \ / | \ _ // /\/
( oo ) \ \ _ // /
//_/\_\/ / |
@ @ / | = \ \ |
\ _ = \ _ \ |
\ = = \ \ | \ _ snd
__ ( \ = = = \ ( ) \
( ( ( ~ ) __ ( _ / |
( ( ( ~ ) \ /
______ / /
' - - - - - - '
*/
2021-12-05 17:54:36 +00:00
LWOOBJID localId ;
2024-02-26 14:17:22 +00:00
inStream . Read ( localId ) ;
2021-12-05 17:54:36 +00:00
2022-10-24 22:20:36 +00:00
uint32_t sd0Size ;
2024-02-26 14:17:22 +00:00
inStream . Read ( sd0Size ) ;
2022-10-24 22:20:36 +00:00
std : : shared_ptr < char [ ] > sd0Data ( new char [ sd0Size ] ) ;
2022-07-17 07:35:11 +00:00
2023-11-06 09:41:28 +00:00
if ( sd0Data = = nullptr ) return ;
2022-07-17 07:35:11 +00:00
2024-02-26 14:17:22 +00:00
inStream . ReadAlignedBytes ( reinterpret_cast < unsigned char * > ( sd0Data . get ( ) ) , sd0Size ) ;
2022-07-17 07:35:11 +00:00
2022-10-24 22:20:36 +00:00
uint32_t timeTaken ;
2024-02-26 14:17:22 +00:00
inStream . Read ( timeTaken ) ;
2021-12-05 17:54:36 +00:00
/*
Disabled this , as it ' s kinda silly to do this roundabout way of storing plaintext lxfml , then recompressing
it to send it back to the client .
On DLU we had agreed that bricks wouldn ' t be taken anyway , but if your server decides otherwise , feel free to
comment this back out and add the needed code to get the bricks used from lxfml and take them from the inventory .
Note , in the live client it ' ll still display the bricks going out as they ' re being used , but on relog / world change ,
they reappear as we didn ' t take them .
2022-10-24 22:20:36 +00:00
TODO Apparently the bricks are supposed to be taken via MoveInventoryBatch ?
2021-12-05 17:54:36 +00:00
*/
////Decompress the SD0 from the client so we can process the lxfml properly
//uint8_t* outData = new uint8_t[327680];
//int32_t error;
//int32_t size = ZCompression::Decompress(inData, lxfmlSize, outData, 327680, error);
//if (size == -1) {
2023-10-21 23:31:55 +00:00
// LOG("Failed to decompress LXFML: (%i)", error);
2021-12-05 17:54:36 +00:00
// return;
//}
//
//std::string lxfml(reinterpret_cast<char*>(outData), size); //std::string version of the decompressed data!
//Now, the cave of dragons:
2022-07-17 07:35:11 +00:00
//We runs this in async because the http library here is blocking, meaning it'll halt the thread.
2021-12-05 17:54:36 +00:00
//But we don't want the server to go unresponsive, because then the client would disconnect.
2023-11-06 09:41:28 +00:00
//We need to get a new ID for our model first:
2024-01-05 12:31:22 +00:00
ObjectIDManager : : RequestPersistentID ( [ = ] ( uint32_t newID ) {
2024-02-04 14:29:05 +00:00
if ( ! entity | | ! entity - > GetCharacter ( ) | | ! entity - > GetCharacter ( ) - > GetParentUser ( ) ) return ;
2023-11-06 09:41:28 +00:00
LWOOBJID newIDL = newID ;
GeneralUtils : : SetBit ( newIDL , eObjectBits : : CHARACTER ) ;
GeneralUtils : : SetBit ( newIDL , eObjectBits : : PERSISTENT ) ;
2021-12-05 17:54:36 +00:00
2024-01-05 12:31:22 +00:00
uint32_t blueprintIDSmall = ObjectIDManager : : GenerateRandomObjectID ( ) ;
2023-11-06 09:41:28 +00:00
LWOOBJID blueprintID = blueprintIDSmall ;
GeneralUtils : : SetBit ( blueprintID , eObjectBits : : CHARACTER ) ;
GeneralUtils : : SetBit ( blueprintID , eObjectBits : : PERSISTENT ) ;
//We need to get the propertyID: (stolen from Wincent's propertyManagementComp)
const auto & worldId = Game : : zoneManager - > GetZone ( ) - > GetZoneID ( ) ;
const auto zoneId = worldId . GetMapID ( ) ;
const auto cloneId = worldId . GetCloneID ( ) ;
2023-11-18 00:47:18 +00:00
auto propertyInfo = Database : : Get ( ) - > GetPropertyInfo ( zoneId , cloneId ) ;
LWOOBJID propertyId = LWOOBJID_EMPTY ;
if ( propertyInfo ) propertyId = propertyInfo - > id ;
2023-11-06 09:41:28 +00:00
//Insert into ugc:
2023-11-18 00:47:18 +00:00
std : : string str ( sd0Data . get ( ) , sd0Size ) ;
std : : istringstream sd0DataStream ( str ) ;
2024-02-04 14:29:05 +00:00
Database : : Get ( ) - > InsertNewUgcModel ( sd0DataStream , blueprintIDSmall , entity - > GetCharacter ( ) - > GetParentUser ( ) - > GetAccountID ( ) , entity - > GetCharacter ( ) - > GetID ( ) ) ;
2023-11-06 09:41:28 +00:00
//Insert into the db as a BBB model:
2023-11-18 00:47:18 +00:00
IPropertyContents : : Model model ;
model . id = newIDL ;
model . ugcId = blueprintIDSmall ;
2024-01-29 07:53:12 +00:00
model . position = NiPoint3Constant : : ZERO ;
2023-11-18 00:47:18 +00:00
model . rotation = NiQuaternion ( 0.0f , 0.0f , 0.0f , 0.0f ) ;
model . lot = 14 ;
Database : : Get ( ) - > InsertNewPropertyModel ( propertyId , model , " Objects_14_name " ) ;
2023-11-06 09:41:28 +00:00
/*
Commented out until UGC server would be updated to use a sd0 file instead of lxfml stream .
( or you uncomment the lxfml decomp stuff above )
*/
////Send off to UGC for processing, if enabled:
//if (Game::config->GetValue("ugc_remote") == "1") {
// std::string ugcIP = Game::config->GetValue("ugc_ip");
// int ugcPort = std::stoi(Game::config->GetValue("ugc_port"));
// httplib::Client cli(ugcIP, ugcPort); //connect to UGC HTTP server using our config above ^
// //Send out a request:
// std::string request = "/3dservices/UGCC150/150" + std::to_string(blueprintID) + ".lxfml";
// cli.Put(request.c_str(), lxfml.c_str(), "text/lxfml");
// //When the "put" above returns, it means that the UGC HTTP server is done processing our model &
// //the nif, hkx and checksum files are ready to be downloaded from cache.
//}
//Tell the client their model is saved: (this causes us to actually pop out of our current state):
CBITSTREAM ;
2024-11-18 00:39:44 +00:00
BitStreamUtils : : WriteHeader ( bitStream , eConnectionType : : CLIENT , MessageType : : Client : : BLUEPRINT_SAVE_RESPONSE ) ;
2023-11-06 09:41:28 +00:00
bitStream . Write ( localId ) ;
bitStream . Write ( eBlueprintSaveResponseType : : EverythingWorked ) ;
bitStream . Write < uint32_t > ( 1 ) ;
bitStream . Write ( blueprintID ) ;
bitStream . Write < uint32_t > ( sd0Size ) ;
bitStream . WriteAlignedBytes ( reinterpret_cast < unsigned char * > ( sd0Data . get ( ) ) , sd0Size ) ;
SEND_PACKET ;
//Now we have to construct this object:
EntityInfo info ;
info . lot = 14 ;
info . pos = { } ;
info . rot = { } ;
info . spawner = nullptr ;
info . spawnerID = entity - > GetObjectID ( ) ;
info . spawnerNodeID = 0 ;
2024-04-05 05:51:40 +00:00
info . settings . push_back ( new LDFData < LWOOBJID > ( u " blueprintid " , blueprintID ) ) ;
info . settings . push_back ( new LDFData < int > ( u " componentWhitelist " , 1 ) ) ;
info . settings . push_back ( new LDFData < int > ( u " modelType " , 2 ) ) ;
info . settings . push_back ( new LDFData < bool > ( u " propertyObjectID " , true ) ) ;
info . settings . push_back ( new LDFData < LWOOBJID > ( u " userModelID " , newIDL ) ) ;
2023-11-06 09:41:28 +00:00
Entity * newEntity = Game : : entityManager - > CreateEntity ( info , nullptr ) ;
if ( newEntity ) {
Game : : entityManager - > ConstructEntity ( newEntity ) ;
//Make sure the propMgmt doesn't delete our model after the server dies
//Trying to do this after the entity is constructed. Shouldn't really change anything but
//there was an issue with builds not appearing since it was placed above ConstructEntity.
PropertyManagementComponent : : Instance ( ) - > AddModel ( newEntity - > GetObjectID ( ) , newIDL ) ;
}
2023-11-16 01:29:53 +00:00
} ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandlePropertyEntranceSync ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
bool includeNullAddress { } ;
bool includeNullDescription { } ;
bool playerOwn { } ;
bool updateUi { } ;
int32_t numResults { } ;
int32_t reputation { } ;
int32_t sortMethod { } ;
int32_t startIndex { } ;
uint32_t filterTextLength { } ;
std : : string filterText { } ;
2024-02-26 14:17:22 +00:00
inStream . Read ( includeNullAddress ) ;
inStream . Read ( includeNullDescription ) ;
inStream . Read ( playerOwn ) ;
inStream . Read ( updateUi ) ;
inStream . Read ( numResults ) ;
inStream . Read ( reputation ) ;
inStream . Read ( sortMethod ) ;
inStream . Read ( startIndex ) ;
inStream . Read ( filterTextLength ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
for ( auto i = 0u ; i < filterTextLength ; i + + ) {
2021-12-05 17:54:36 +00:00
char c ;
2024-02-26 14:17:22 +00:00
inStream . Read ( c ) ;
2021-12-05 17:54:36 +00:00
filterText . push_back ( c ) ;
}
2024-01-13 09:40:56 +00:00
auto * player = PlayerManager : : GetPlayer ( sysAddr ) ;
2021-12-05 17:54:36 +00:00
auto * entranceComponent = entity - > GetComponent < PropertyEntranceComponent > ( ) ;
if ( entranceComponent = = nullptr ) return ;
entranceComponent - > OnPropertyEntranceSync ( player ,
includeNullAddress ,
includeNullDescription ,
playerOwn ,
updateUi ,
numResults ,
reputation ,
sortMethod ,
startIndex ,
filterText ,
sysAddr
) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleEnterProperty ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
uint32_t index { } ;
bool returnToZone { } ;
2024-02-26 14:17:22 +00:00
inStream . Read ( index ) ;
inStream . Read ( returnToZone ) ;
2021-12-05 17:54:36 +00:00
2024-01-13 09:40:56 +00:00
auto * player = PlayerManager : : GetPlayer ( sysAddr ) ;
2021-12-05 17:54:36 +00:00
auto * entranceComponent = entity - > GetComponent < PropertyEntranceComponent > ( ) ;
2022-05-03 20:05:29 +00:00
if ( entranceComponent ! = nullptr ) {
entranceComponent - > OnEnterProperty ( player , index , returnToZone , sysAddr ) ;
return ;
}
2021-12-05 17:54:36 +00:00
2023-08-18 19:14:40 +00:00
auto multiZoneEntranceComponent = entity - > GetComponent < MultiZoneEntranceComponent > ( ) ;
if ( multiZoneEntranceComponent ! = nullptr ) {
multiZoneEntranceComponent - > OnSelectWorld ( player , index ) ;
2022-05-03 20:05:29 +00:00
}
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleSetConsumableItem ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
LOT lot ;
2024-02-26 14:17:22 +00:00
inStream . Read ( lot ) ;
2021-12-05 17:54:36 +00:00
auto * inventory = entity - > GetComponent < InventoryComponent > ( ) ;
if ( inventory = = nullptr ) return ;
inventory - > SetConsumable ( lot ) ;
}
2022-07-17 07:35:11 +00:00
void GameMessages : : SendPlayCinematic ( LWOOBJID objectId , std : : u16string pathName , const SystemAddress & sysAddr ,
2022-07-28 13:39:57 +00:00
bool allowGhostUpdates , bool bCloseMultiInteract , bool bSendServerNotify , bool bUseControlledObjectForAudioListener ,
2023-03-25 10:26:39 +00:00
eEndBehavior endBehavior , bool hidePlayerDuringCine , float leadIn , bool leavePlayerLockedWhenFinished ,
2022-07-28 13:39:57 +00:00
bool lockPlayer , bool result , bool skipIfSamePath , float startTimeAdvance ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PLAY_CINEMATIC ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( allowGhostUpdates ) ;
bitStream . Write ( bCloseMultiInteract ) ;
bitStream . Write ( bSendServerNotify ) ;
bitStream . Write ( bUseControlledObjectForAudioListener ) ;
2023-03-25 10:26:39 +00:00
bitStream . Write ( endBehavior ! = eEndBehavior : : RETURN ) ;
if ( endBehavior ! = eEndBehavior : : RETURN ) bitStream . Write ( endBehavior ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( hidePlayerDuringCine ) ;
bitStream . Write ( leadIn ! = - 1 ) ;
if ( leadIn ! = - 1 ) bitStream . Write ( leadIn ) ;
bitStream . Write ( leavePlayerLockedWhenFinished ) ;
bitStream . Write ( lockPlayer ) ;
bitStream . Write < uint32_t > ( pathName . size ( ) ) ;
for ( char16_t c : pathName ) {
bitStream . Write ( c ) ;
}
bitStream . Write ( result ) ;
bitStream . Write ( skipIfSamePath ) ;
bitStream . Write ( startTimeAdvance ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
void GameMessages : : SendEndCinematic ( LWOOBJID objectId , std : : u16string pathName , const SystemAddress & sysAddr ,
2022-07-28 13:39:57 +00:00
float leadOut , bool leavePlayerLocked ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : END_CINEMATIC ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( leadOut ! = - 1 ) ;
if ( leadOut ! = - 1 ) bitStream . Write ( leadOut ) ;
bitStream . Write ( leavePlayerLocked ) ;
bitStream . Write < uint32_t > ( pathName . size ( ) ) ;
for ( uint32_t i = 0 ; i < pathName . size ( ) ; i + + ) {
bitStream . Write ( pathName [ i ] ) ;
}
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleCinematicUpdate ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2022-07-23 02:58:20 +00:00
eCinematicEvent event ;
2024-02-26 14:17:22 +00:00
if ( ! inStream . ReadBit ( ) ) {
2023-05-02 22:39:21 +00:00
event = eCinematicEvent : : STARTED ;
2022-07-23 02:58:20 +00:00
} else {
2024-02-26 14:17:22 +00:00
inStream . Read < eCinematicEvent > ( event ) ;
2022-07-23 02:58:20 +00:00
}
float_t overallTime ;
2024-02-26 14:17:22 +00:00
if ( ! inStream . ReadBit ( ) ) {
2022-07-23 02:58:20 +00:00
overallTime = - 1.0f ;
} else {
2024-02-26 14:17:22 +00:00
inStream . Read < float_t > ( overallTime ) ;
2022-07-23 02:58:20 +00:00
}
uint32_t pathNameLength ;
2024-02-26 14:17:22 +00:00
inStream . Read ( pathNameLength ) ;
2022-07-23 02:58:20 +00:00
std : : u16string pathName ;
for ( size_t i = 0 ; i < pathNameLength ; i + + ) {
char16_t character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2022-07-23 02:58:20 +00:00
pathName . push_back ( character ) ;
}
float_t pathTime ;
2024-02-26 14:17:22 +00:00
if ( ! inStream . ReadBit ( ) ) {
2022-07-23 02:58:20 +00:00
pathTime = - 1.0f ;
} else {
2024-02-26 14:17:22 +00:00
inStream . Read < float_t > ( pathTime ) ;
2022-07-23 02:58:20 +00:00
}
int32_t waypoint ;
2024-02-26 14:17:22 +00:00
if ( ! inStream . ReadBit ( ) ) {
2022-07-23 02:58:20 +00:00
waypoint = - 1 ;
} else {
2024-02-26 14:17:22 +00:00
inStream . Read < int32_t > ( waypoint ) ;
2022-07-23 02:58:20 +00:00
}
2023-07-15 20:56:33 +00:00
std : : vector < Entity * > scriptedActs = Game : : entityManager - > GetEntitiesByComponent ( eReplicaComponentType : : SCRIPT ) ;
2022-07-23 02:58:20 +00:00
for ( Entity * scriptEntity : scriptedActs ) {
scriptEntity - > OnCinematicUpdate ( scriptEntity , entity , event , pathName , pathTime , overallTime , waypoint ) ;
}
2021-12-05 17:54:36 +00:00
}
2023-01-07 05:59:19 +00:00
void GameMessages : : SendSetStunned ( LWOOBJID objectId , eStateChangeType stateChangeType , const SystemAddress & sysAddr ,
2022-07-28 13:39:57 +00:00
LWOOBJID originator , bool bCantAttack , bool bCantEquip ,
bool bCantInteract , bool bCantJump , bool bCantMove , bool bCantTurn ,
bool bCantUseItem , bool bDontTerminateInteract , bool bIgnoreImmunity ,
bool bCantAttackOutChangeWasApplied , bool bCantEquipOutChangeWasApplied ,
bool bCantInteractOutChangeWasApplied , bool bCantJumpOutChangeWasApplied ,
bool bCantMoveOutChangeWasApplied , bool bCantTurnOutChangeWasApplied ,
bool bCantUseItemOutChangeWasApplied ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_STUNNED ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( originator ! = LWOOBJID_EMPTY ) ;
if ( originator ! = LWOOBJID_EMPTY ) bitStream . Write ( originator ) ;
bitStream . Write ( stateChangeType ) ;
bitStream . Write ( bCantAttack ) ;
bitStream . Write ( bCantAttackOutChangeWasApplied ) ;
bitStream . Write ( bCantEquip ) ;
bitStream . Write ( bCantEquipOutChangeWasApplied ) ;
bitStream . Write ( bCantInteract ) ;
bitStream . Write ( bCantInteractOutChangeWasApplied ) ;
bitStream . Write ( bCantJump ) ;
bitStream . Write ( bCantJumpOutChangeWasApplied ) ;
bitStream . Write ( bCantMove ) ;
bitStream . Write ( bCantMoveOutChangeWasApplied ) ;
bitStream . Write ( bCantTurn ) ;
bitStream . Write ( bCantTurnOutChangeWasApplied ) ;
bitStream . Write ( bCantUseItem ) ;
bitStream . Write ( bCantUseItemOutChangeWasApplied ) ;
bitStream . Write ( bDontTerminateInteract ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
bitStream . Write ( bIgnoreImmunity ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2023-01-07 05:59:19 +00:00
void GameMessages : : SendSetStunImmunity ( LWOOBJID target , eStateChangeType state , const SystemAddress & sysAddr ,
2023-10-16 12:55:57 +00:00
LWOOBJID originator ,
bool bImmuneToStunAttack ,
bool bImmuneToStunEquip ,
bool bImmuneToStunInteract ,
bool bImmuneToStunJump ,
bool bImmuneToStunMove ,
bool bImmuneToStunTurn ,
bool bImmuneToStunUseItem ) {
2023-01-07 05:59:19 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( target ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_STUN_IMMUNITY ) ;
2023-01-07 05:59:19 +00:00
bitStream . Write ( originator ! = LWOOBJID_EMPTY ) ;
if ( originator ! = LWOOBJID_EMPTY ) bitStream . Write ( originator ) ;
bitStream . Write ( state ) ;
bitStream . Write ( bImmuneToStunAttack ) ;
bitStream . Write ( bImmuneToStunEquip ) ;
bitStream . Write ( bImmuneToStunInteract ) ;
bitStream . Write ( bImmuneToStunJump ) ;
bitStream . Write ( bImmuneToStunMove ) ;
bitStream . Write ( bImmuneToStunTurn ) ;
bitStream . Write ( bImmuneToStunUseItem ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
void GameMessages : : SendSetStatusImmunity ( LWOOBJID objectId , eStateChangeType state , const SystemAddress & sysAddr ,
2023-10-16 12:55:57 +00:00
bool bImmuneToBasicAttack ,
bool bImmuneToDamageOverTime ,
bool bImmuneToKnockback ,
bool bImmuneToInterrupt ,
bool bImmuneToSpeed ,
bool bImmuneToImaginationGain ,
bool bImmuneToImaginationLoss ,
bool bImmuneToQuickbuildInterrupt ,
bool bImmuneToPullToPoint ) {
2023-01-07 05:59:19 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_STATUS_IMMUNITY ) ;
2023-01-07 05:59:19 +00:00
bitStream . Write ( state ) ;
bitStream . Write ( bImmuneToBasicAttack ) ;
bitStream . Write ( bImmuneToDamageOverTime ) ;
bitStream . Write ( bImmuneToKnockback ) ;
bitStream . Write ( bImmuneToInterrupt ) ;
bitStream . Write ( bImmuneToSpeed ) ;
bitStream . Write ( bImmuneToImaginationGain ) ;
bitStream . Write ( bImmuneToImaginationLoss ) ;
bitStream . Write ( bImmuneToQuickbuildInterrupt ) ;
bitStream . Write ( bImmuneToPullToPoint ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
void GameMessages : : SendOrientToAngle ( LWOOBJID objectId , bool bRelativeToCurrent , float fAngle , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : ORIENT_TO_ANGLE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bRelativeToCurrent ) ;
bitStream . Write ( fAngle ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendAddRunSpeedModifier ( LWOOBJID objectId , LWOOBJID caster , uint32_t modifier , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : ADD_RUN_SPEED_MODIFIER ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( caster ! = LWOOBJID_EMPTY ) ;
if ( caster ! = LWOOBJID_EMPTY ) bitStream . Write ( caster ) ;
bitStream . Write ( modifier ! = 500 ) ;
if ( modifier ! = 500 ) bitStream . Write ( modifier ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendRemoveRunSpeedModifier ( LWOOBJID objectId , uint32_t modifier , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : REMOVE_RUN_SPEED_MODIFIER ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( modifier ! = 500 ) ;
if ( modifier ! = 500 ) bitStream . Write ( modifier ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendPropertyEntranceBegin ( LWOOBJID objectId , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PROPERTY_ENTRANCE_BEGIN ) ;
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendPropertySelectQuery ( LWOOBJID objectId , int32_t navOffset , bool thereAreMore , int32_t cloneId , bool hasFeaturedProperty , bool wasFriends , const std : : vector < PropertySelectQueryProperty > & entries , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PROPERTY_SELECT_QUERY ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( navOffset ) ;
bitStream . Write ( thereAreMore ) ;
bitStream . Write ( cloneId ) ;
bitStream . Write ( hasFeaturedProperty ) ;
bitStream . Write ( wasFriends ) ;
bitStream . Write < uint32_t > ( entries . size ( ) ) ;
2022-07-28 13:39:57 +00:00
for ( auto & entry : entries ) {
2021-12-05 17:54:36 +00:00
entry . Serialize ( bitStream ) ;
}
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendNotifyObject ( LWOOBJID objectId , LWOOBJID objIDSender , std : : u16string name , const SystemAddress & sysAddr , int param1 , int param2 ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : NOTIFY_OBJECT ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( objIDSender ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( name . size ( ) ) ;
2022-07-28 13:39:57 +00:00
for ( const auto character : name ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( character ) ;
}
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
bitStream . Write ( param1 ) ;
bitStream . Write ( param2 ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleVerifyAck ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
bool bDifferent ;
std : : string sBitStream ;
uint32_t uiHandle = 0 ;
2024-02-26 14:17:22 +00:00
bDifferent = inStream . ReadBit ( ) ;
2021-12-05 17:54:36 +00:00
uint32_t sBitStreamLength = 0 ;
2024-02-26 14:17:22 +00:00
inStream . Read ( sBitStreamLength ) ;
2021-12-05 17:54:36 +00:00
for ( uint64_t k = 0 ; k < sBitStreamLength ; k + + ) {
uint8_t character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2021-12-05 17:54:36 +00:00
sBitStream . push_back ( character ) ;
}
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) {
inStream . Read ( uiHandle ) ;
2021-12-05 17:54:36 +00:00
}
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendTeamPickupItem ( LWOOBJID objectId , LWOOBJID lootID , LWOOBJID lootOwnerID , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : TEAM_PICKUP_ITEM ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( lootID ) ;
bitStream . Write ( lootOwnerID ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
//Trading:
2022-07-28 13:39:57 +00:00
void GameMessages : : SendServerTradeInvite ( LWOOBJID objectId , bool bNeedInvitePopUp , LWOOBJID i64Requestor , std : : u16string wsName , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SERVER_TRADE_INVITE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bNeedInvitePopUp ) ;
bitStream . Write ( i64Requestor ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( wsName . size ( ) ) ;
2022-07-28 13:39:57 +00:00
for ( const auto character : wsName ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( character ) ;
}
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendServerTradeInitialReply ( LWOOBJID objectId , LWOOBJID i64Invitee , int32_t resultType , std : : u16string wsName , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SERVER_TRADE_INITIAL_REPLY ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( i64Invitee ) ;
bitStream . Write ( resultType ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( wsName . size ( ) ) ;
2022-07-28 13:39:57 +00:00
for ( const auto character : wsName ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( character ) ;
}
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendServerTradeFinalReply ( LWOOBJID objectId , bool bResult , LWOOBJID i64Invitee , std : : u16string wsName , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SERVER_TRADE_FINAL_REPLY ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bResult ) ;
bitStream . Write ( i64Invitee ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( wsName . size ( ) ) ;
2022-07-28 13:39:57 +00:00
for ( const auto character : wsName ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( character ) ;
}
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendServerTradeAccept ( LWOOBJID objectId , bool bFirst , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SERVER_TRADE_ACCEPT ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bFirst ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendServerTradeCancel ( LWOOBJID objectId , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SERVER_TRADE_CANCEL ) ;
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendServerTradeUpdate ( LWOOBJID objectId , uint64_t coins , const std : : vector < TradeItem > & items , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SERVER_TRADE_UPDATE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( false ) ;
bitStream . Write ( coins ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( items . size ( ) ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
for ( const auto & item : items ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( item . itemId ) ;
bitStream . Write ( item . itemId ) ;
bitStream . Write ( item . itemLot ) ;
bitStream . Write0 ( ) ;
bitStream . Write1 ( ) ;
bitStream . Write ( item . itemCount ) ;
bitStream . Write0 ( ) ;
bitStream . Write0 ( ) ;
bitStream . Write0 ( ) ;
bitStream . Write0 ( ) ;
}
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleClientTradeRequest ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
// Check if the player has restricted trade access
auto * character = entity - > GetCharacter ( ) ;
2023-01-22 23:38:47 +00:00
if ( character - > HasPermission ( ePermissionMap : : RestrictedTradeAccess ) ) {
2021-12-05 17:54:36 +00:00
// Send a message to the player
ChatPackets : : SendSystemMessage (
sysAddr ,
u " This character has restricted trade access. "
) ;
return ;
}
2024-02-26 14:17:22 +00:00
bool bNeedInvitePopUp = inStream . ReadBit ( ) ;
2021-12-05 17:54:36 +00:00
LWOOBJID i64Invitee ;
2024-02-26 14:17:22 +00:00
inStream . Read ( i64Invitee ) ;
2021-12-05 17:54:36 +00:00
2023-07-15 20:56:33 +00:00
auto * invitee = Game : : entityManager - > GetEntity ( i64Invitee ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( invitee ! = nullptr & & invitee - > IsPlayer ( ) ) {
2021-12-05 17:54:36 +00:00
character = invitee - > GetCharacter ( ) ;
2023-01-22 23:38:47 +00:00
if ( character - > HasPermission ( ePermissionMap : : RestrictedTradeAccess ) ) {
2021-12-05 17:54:36 +00:00
// Send a message to the player
ChatPackets : : SendSystemMessage (
sysAddr ,
u " The character you are trying to trade with has restricted trade access. "
) ;
return ;
}
2023-10-21 23:31:55 +00:00
LOG ( " Trade request to (%llu) " , i64Invitee ) ;
2021-12-05 17:54:36 +00:00
auto * trade = TradingManager : : Instance ( ) - > GetPlayerTrade ( entity - > GetObjectID ( ) ) ;
2022-07-28 13:39:57 +00:00
if ( trade ! = nullptr ) {
if ( ! trade - > IsParticipant ( i64Invitee ) ) {
2024-02-12 03:00:39 +00:00
TradingManager : : Instance ( ) - > CancelTrade ( entity - > GetObjectID ( ) , trade - > GetTradeId ( ) ) ;
2021-12-05 17:54:36 +00:00
TradingManager : : Instance ( ) - > NewTrade ( entity - > GetObjectID ( ) , i64Invitee ) ;
}
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
TradingManager : : Instance ( ) - > NewTrade ( entity - > GetObjectID ( ) , i64Invitee ) ;
}
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
SendServerTradeInvite (
i64Invitee ,
bNeedInvitePopUp ,
entity - > GetObjectID ( ) ,
2022-08-02 13:56:20 +00:00
GeneralUtils : : UTF8ToUTF16 ( entity - > GetCharacter ( ) - > GetName ( ) ) ,
2021-12-05 17:54:36 +00:00
invitee - > GetSystemAddress ( )
) ;
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleClientTradeCancel ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
auto * trade = TradingManager : : Instance ( ) - > GetPlayerTrade ( entity - > GetObjectID ( ) ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
if ( trade = = nullptr ) return ;
2023-10-21 23:31:55 +00:00
LOG ( " Trade canceled from (%llu) " , entity - > GetObjectID ( ) ) ;
2022-04-09 02:36:43 +00:00
2024-02-12 03:00:39 +00:00
TradingManager : : Instance ( ) - > CancelTrade ( entity - > GetObjectID ( ) , trade - > GetTradeId ( ) ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleClientTradeAccept ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
bool bFirst = inStream . ReadBit ( ) ;
2021-12-05 17:54:36 +00:00
2023-10-21 23:31:55 +00:00
LOG ( " Trade accepted from (%llu) -> (%d) " , entity - > GetObjectID ( ) , bFirst ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
auto * trade = TradingManager : : Instance ( ) - > GetPlayerTrade ( entity - > GetObjectID ( ) ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
if ( trade = = nullptr ) return ;
trade - > SetAccepted ( entity - > GetObjectID ( ) , bFirst ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleClientTradeUpdate ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
uint64_t currency ;
uint32_t itemCount ;
2024-02-26 14:17:22 +00:00
inStream . Read ( currency ) ;
inStream . Read ( itemCount ) ;
2021-12-05 17:54:36 +00:00
2023-10-21 23:31:55 +00:00
LOG ( " Trade update from (%llu) -> (%llu), (%i) " , entity - > GetObjectID ( ) , currency , itemCount ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
std : : vector < TradeItem > items { } ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
for ( size_t i = 0 ; i < itemCount ; i + + ) {
2021-12-05 17:54:36 +00:00
LWOOBJID itemId ;
LWOOBJID itemId2 ;
2024-02-26 14:17:22 +00:00
inStream . Read ( itemId ) ;
inStream . Read ( itemId2 ) ;
2021-12-05 17:54:36 +00:00
LOT lot = 0 ;
LWOOBJID unknown1 = 0 ;
uint32_t unknown2 = 0 ;
uint16_t slot = 0 ;
uint32_t unknown3 = 0 ;
uint32_t ldfSize = 0 ;
bool unknown4 ;
2024-02-26 14:17:22 +00:00
inStream . Read ( lot ) ;
if ( inStream . ReadBit ( ) ) {
inStream . Read ( unknown1 ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) {
inStream . Read ( unknown2 ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) {
inStream . Read ( slot ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) {
inStream . Read ( unknown3 ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) // No
2021-12-05 17:54:36 +00:00
{
2024-02-26 14:17:22 +00:00
inStream . Read ( ldfSize ) ;
bool compressed = inStream . ReadBit ( ) ;
2022-07-28 13:39:57 +00:00
if ( compressed ) {
2021-12-05 17:54:36 +00:00
uint32_t ldfCompressedSize = 0 ;
2024-02-26 14:17:22 +00:00
inStream . Read ( ldfCompressedSize ) ;
inStream . IgnoreBytes ( ldfCompressedSize ) ;
2022-07-28 13:39:57 +00:00
} else {
2024-02-26 14:17:22 +00:00
inStream . IgnoreBytes ( ldfSize ) ;
2021-12-05 17:54:36 +00:00
}
}
2024-02-26 14:17:22 +00:00
unknown4 = inStream . ReadBit ( ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
items . push_back ( { itemId , lot , unknown2 } ) ;
2021-12-05 17:54:36 +00:00
2023-10-21 23:31:55 +00:00
LOG ( " Trade item from (%llu) -> (%llu)/(%llu), (%i), (%llu), (%i), (%i) " , entity - > GetObjectID ( ) , itemId , itemId2 , lot , unknown1 , unknown2 , unknown3 ) ;
2021-12-05 17:54:36 +00:00
}
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
auto * trade = TradingManager : : Instance ( ) - > GetPlayerTrade ( entity - > GetObjectID ( ) ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
if ( trade = = nullptr ) return ;
trade - > SetCoins ( entity - > GetObjectID ( ) , currency ) ;
trade - > SetItems ( entity - > GetObjectID ( ) , items ) ;
trade - > SendUpdateToOther ( entity - > GetObjectID ( ) ) ;
}
//Pets:
2023-05-02 22:39:21 +00:00
void GameMessages : : SendNotifyPetTamingMinigame ( LWOOBJID objectId , LWOOBJID petId , LWOOBJID playerTamingId , bool bForceTeleport , ePetTamingNotifyType notifyType , NiPoint3 petsDestPos , NiPoint3 telePos , NiQuaternion teleRot , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : NOTIFY_PET_TAMING_MINIGAME ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( petId ) ;
bitStream . Write ( playerTamingId ) ;
bitStream . Write ( bForceTeleport ) ;
bitStream . Write ( notifyType ) ;
bitStream . Write ( petsDestPos ) ;
bitStream . Write ( telePos ) ;
2024-01-29 07:53:12 +00:00
const bool hasDefault = teleRot ! = NiQuaternionConstant : : IDENTITY ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( hasDefault ) ;
if ( hasDefault ) bitStream . Write ( teleRot ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendNotifyTamingModelLoadedOnServer ( LWOOBJID objectId , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : NOTIFY_TAMING_MODEL_LOADED_ON_SERVER ) ;
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2023-07-17 22:55:25 +00:00
void GameMessages : : SendNotifyPetTamingPuzzleSelected ( LWOOBJID objectId , const std : : vector < Brick > & bricks , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : NOTIFY_TAMING_PUZZLE_SELECTED ) ;
2021-12-05 17:54:36 +00:00
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( bricks . size ( ) ) ;
2022-07-28 13:39:57 +00:00
for ( const auto & brick : bricks ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( brick . designerID ) ;
bitStream . Write ( brick . materialID ) ;
}
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendPetTamingTryBuildResult ( LWOOBJID objectId , bool bSuccess , int32_t iNumCorrect , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PET_TAMING_TRY_BUILD_RESULT ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bSuccess ) ;
bitStream . Write ( iNumCorrect ! = 0 ) ;
if ( iNumCorrect ! = 0 ) bitStream . Write ( iNumCorrect ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendPetResponse ( LWOOBJID objectId , LWOOBJID objIDPet , int32_t iPetCommandType , int32_t iResponse , int32_t iTypeID , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PET_RESPONSE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( objIDPet ) ;
bitStream . Write ( iPetCommandType ) ;
bitStream . Write ( iResponse ) ;
bitStream . Write ( iTypeID ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendAddPetToPlayer ( LWOOBJID objectId , int32_t iElementalType , std : : u16string name , LWOOBJID petDBID , LOT petLOT , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : ADD_PET_TO_PLAYER ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( iElementalType ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( name . size ( ) ) ;
2022-07-28 13:39:57 +00:00
for ( const auto character : name ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( character ) ;
}
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
bitStream . Write ( petDBID ) ;
bitStream . Write ( petLOT ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendRegisterPetID ( LWOOBJID objectId , LWOOBJID objID , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : REGISTER_PET_ID ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( objID ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendRegisterPetDBID ( LWOOBJID objectId , LWOOBJID petDBID , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : REGISTER_PET_DBID ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( petDBID ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-09-02 18:49:19 +00:00
void GameMessages : : SendMarkInventoryItemAsActive ( LWOOBJID objectId , bool bActive , eUnequippableActiveType iType , LWOOBJID itemID , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : MARK_INVENTORY_ITEM_AS_ACTIVE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bActive ) ;
2022-07-17 07:35:11 +00:00
2022-09-02 18:49:19 +00:00
bitStream . Write ( iType ! = eUnequippableActiveType : : INVALID ) ;
if ( iType ! = eUnequippableActiveType : : INVALID ) bitStream . Write ( iType ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( itemID ! = LWOOBJID_EMPTY ) ;
if ( itemID ! = LWOOBJID_EMPTY ) bitStream . Write ( itemID ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendClientExitTamingMinigame ( LWOOBJID objectId , bool bVoluntaryExit , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : CLIENT_EXIT_TAMING_MINIGAME ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bVoluntaryExit ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2024-01-08 23:32:09 +00:00
void GameMessages : : SendShowPetActionButton ( const LWOOBJID objectId , const ePetAbilityType petAbility , const bool bShow , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SHOW_PET_ACTION_BUTTON ) ;
2021-12-05 17:54:36 +00:00
2024-01-08 23:32:09 +00:00
bitStream . Write ( petAbility ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bShow ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendPlayEmote ( LWOOBJID objectId , int32_t emoteID , LWOOBJID target , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PLAY_EMOTE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( emoteID ) ;
bitStream . Write ( target ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-11-28 00:40:14 +00:00
void GameMessages : : SendRemoveBuff ( Entity * entity , bool fromUnEquip , bool removeImmunity , uint32_t buffId ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : REMOVE_BUFF ) ;
2022-11-28 00:40:14 +00:00
bitStream . Write ( false ) ; // bFromRemoveBehavior but setting this to true makes the GM not do anything on the client?
bitStream . Write ( fromUnEquip ) ;
bitStream . Write ( removeImmunity ) ;
bitStream . Write ( buffId ) ;
SEND_PACKET_BROADCAST ;
}
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
void GameMessages : : SendBouncerActiveStatus ( LWOOBJID objectId , bool bActive , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : BOUNCER_ACTIVE_STATUS ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bActive ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendSetPetName ( LWOOBJID objectId , std : : u16string name , LWOOBJID petDBID , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_PET_NAME ) ;
2021-12-05 17:54:36 +00:00
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( name . size ( ) ) ;
2022-07-28 13:39:57 +00:00
for ( const auto character : name ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( character ) ;
}
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
bitStream . Write ( petDBID ! = LWOOBJID_EMPTY ) ;
if ( petDBID ! = LWOOBJID_EMPTY ) bitStream . Write ( petDBID ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendSetPetNameModerated ( LWOOBJID objectId , LWOOBJID petDBID , int32_t nModerationStatus , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_PET_NAME_MODERATED ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
bitStream . Write ( petDBID ! = LWOOBJID_EMPTY ) ;
if ( petDBID ! = LWOOBJID_EMPTY ) bitStream . Write ( petDBID ) ;
bitStream . Write ( nModerationStatus ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendPetNameChanged ( LWOOBJID objectId , int32_t moderationStatus , std : : u16string name , std : : u16string ownerName , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : PET_NAME_CHANGED ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( moderationStatus ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( name . size ( ) ) ;
2022-07-28 13:39:57 +00:00
for ( const auto character : name ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( character ) ;
}
2022-07-17 07:35:11 +00:00
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( ownerName . size ( ) ) ;
2022-07-28 13:39:57 +00:00
for ( const auto character : ownerName ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( character ) ;
}
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleClientExitTamingMinigame ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
bool bVoluntaryExit = inStream . ReadBit ( ) ;
2021-12-05 17:54:36 +00:00
auto * petComponent = PetComponent : : GetTamingPet ( entity - > GetObjectID ( ) ) ;
2022-07-28 13:39:57 +00:00
if ( petComponent = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
petComponent - > ClientExitTamingMinigame ( bVoluntaryExit ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleStartServerPetMinigameTimer ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
auto * petComponent = PetComponent : : GetTamingPet ( entity - > GetObjectID ( ) ) ;
2022-07-28 13:39:57 +00:00
if ( petComponent = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
petComponent - > StartTimer ( ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandlePetTamingTryBuild ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
uint32_t brickCount ;
std : : vector < Brick > bricks ;
bool clientFailed ;
2024-02-26 14:17:22 +00:00
inStream . Read ( brickCount ) ;
2021-12-05 17:54:36 +00:00
bricks . reserve ( brickCount ) ;
2022-07-28 13:39:57 +00:00
for ( uint32_t i = 0 ; i < brickCount ; i + + ) {
2021-12-05 17:54:36 +00:00
Brick brick ;
2024-02-26 14:17:22 +00:00
inStream . Read ( brick ) ;
2021-12-05 17:54:36 +00:00
bricks . push_back ( brick ) ;
}
2024-02-26 14:17:22 +00:00
clientFailed = inStream . ReadBit ( ) ;
2021-12-05 17:54:36 +00:00
auto * petComponent = PetComponent : : GetTamingPet ( entity - > GetObjectID ( ) ) ;
2022-07-28 13:39:57 +00:00
if ( petComponent = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
2022-04-07 05:21:17 +00:00
petComponent - > TryBuild ( bricks . size ( ) , clientFailed ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleNotifyTamingBuildSuccess ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
NiPoint3 position ;
2024-02-26 14:17:22 +00:00
inStream . Read ( position ) ;
2021-12-05 17:54:36 +00:00
auto * petComponent = PetComponent : : GetTamingPet ( entity - > GetObjectID ( ) ) ;
2022-07-28 13:39:57 +00:00
if ( petComponent = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
petComponent - > NotifyTamingBuildSuccess ( position ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleRequestSetPetName ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
uint32_t nameLength ;
std : : u16string name ;
2024-02-26 14:17:22 +00:00
inStream . Read ( nameLength ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
for ( size_t i = 0 ; i < nameLength ; i + + ) {
2021-12-05 17:54:36 +00:00
char16_t character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2021-12-05 17:54:36 +00:00
name . push_back ( character ) ;
}
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
auto * petComponent = PetComponent : : GetTamingPet ( entity - > GetObjectID ( ) ) ;
2022-07-28 13:39:57 +00:00
if ( petComponent = = nullptr ) {
2021-12-05 17:54:36 +00:00
petComponent = PetComponent : : GetActivePet ( entity - > GetObjectID ( ) ) ;
2022-07-28 13:39:57 +00:00
if ( petComponent = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
}
petComponent - > RequestSetPetName ( name ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleCommandPet ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
NiPoint3 genericPosInfo ;
LWOOBJID objIdSource ;
int32_t iPetCommandType ;
int32_t iTypeID ;
bool overrideObey ;
2022-07-17 07:35:11 +00:00
2024-02-26 14:17:22 +00:00
inStream . Read ( genericPosInfo ) ;
inStream . Read ( objIdSource ) ;
inStream . Read ( iPetCommandType ) ;
inStream . Read ( iTypeID ) ;
overrideObey = inStream . ReadBit ( ) ;
2021-12-05 17:54:36 +00:00
auto * petComponent = entity - > GetComponent < PetComponent > ( ) ;
2022-07-28 13:39:57 +00:00
if ( petComponent = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
petComponent - > Command ( genericPosInfo , objIdSource , iPetCommandType , iTypeID , overrideObey ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleDespawnPet ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
bool bDeletePet ;
2024-02-26 14:17:22 +00:00
bDeletePet = inStream . ReadBit ( ) ;
2021-12-05 17:54:36 +00:00
auto * petComponent = PetComponent : : GetActivePet ( entity - > GetObjectID ( ) ) ;
2022-07-28 13:39:57 +00:00
if ( petComponent = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
2022-07-28 13:39:57 +00:00
if ( bDeletePet ) {
2021-12-05 17:54:36 +00:00
petComponent - > Release ( ) ;
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
petComponent - > Deactivate ( ) ;
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleMessageBoxResponse ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
int32_t iButton ;
uint32_t identifierLength ;
std : : u16string identifier ;
uint32_t userDataLength ;
std : : u16string userData ;
2024-02-26 14:17:22 +00:00
inStream . Read ( iButton ) ;
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
inStream . Read ( identifierLength ) ;
2022-07-28 13:39:57 +00:00
for ( size_t i = 0 ; i < identifierLength ; i + + ) {
2021-12-05 17:54:36 +00:00
char16_t character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2021-12-05 17:54:36 +00:00
identifier . push_back ( character ) ;
}
2024-02-26 14:17:22 +00:00
inStream . Read ( userDataLength ) ;
2022-07-28 13:39:57 +00:00
for ( size_t i = 0 ; i < userDataLength ; i + + ) {
2021-12-05 17:54:36 +00:00
char16_t character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2021-12-05 17:54:36 +00:00
userData . push_back ( character ) ;
}
2022-07-17 07:35:11 +00:00
2023-10-21 23:31:55 +00:00
LOG ( " Button: %d; LOT: %u identifier: %s; userData: %s " , iButton , entity - > GetLOT ( ) , GeneralUtils : : UTF16ToWTF8 ( identifier ) . c_str ( ) , GeneralUtils : : UTF16ToWTF8 ( userData ) . c_str ( ) ) ;
2021-12-05 17:54:36 +00:00
auto * user = UserManager : : Instance ( ) - > GetUser ( sysAddr ) ;
2022-07-28 13:39:57 +00:00
if ( user = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
auto * userEntity = user - > GetLastUsedChar ( ) - > GetEntity ( ) ;
2022-07-28 13:39:57 +00:00
if ( userEntity = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
entity - > OnMessageBoxResponse ( userEntity , iButton , identifier , userData ) ;
auto * scriptedActivityComponent = entity - > GetComponent < ScriptedActivityComponent > ( ) ;
2022-07-28 13:39:57 +00:00
if ( scriptedActivityComponent ! = nullptr ) {
2021-12-05 17:54:36 +00:00
scriptedActivityComponent - > HandleMessageBoxResponse ( userEntity , GeneralUtils : : UTF16ToWTF8 ( identifier ) ) ;
}
auto * racingControlComponent = entity - > GetComponent < RacingControlComponent > ( ) ;
2022-07-28 13:39:57 +00:00
if ( racingControlComponent ! = nullptr ) {
2023-05-09 05:40:00 +00:00
racingControlComponent - > HandleMessageBoxResponse ( userEntity , iButton , GeneralUtils : : UTF16ToWTF8 ( identifier ) ) ;
2021-12-05 17:54:36 +00:00
}
2023-07-15 20:56:33 +00:00
for ( auto * shootingGallery : Game : : entityManager - > GetEntitiesByComponent ( eReplicaComponentType : : SHOOTING_GALLERY ) ) {
2021-12-05 17:54:36 +00:00
shootingGallery - > OnMessageBoxResponse ( userEntity , iButton , identifier , userData ) ;
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleChoiceBoxRespond ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
int32_t iButton ;
uint32_t buttonIdentifierLength ;
std : : u16string buttonIdentifier ;
uint32_t identifierLength ;
std : : u16string identifier ;
2024-02-26 14:17:22 +00:00
inStream . Read ( buttonIdentifierLength ) ;
2022-07-28 13:39:57 +00:00
for ( size_t i = 0 ; i < buttonIdentifierLength ; i + + ) {
2021-12-05 17:54:36 +00:00
char16_t character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2021-12-05 17:54:36 +00:00
buttonIdentifier . push_back ( character ) ;
}
2024-02-26 14:17:22 +00:00
inStream . Read ( iButton ) ;
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
inStream . Read ( identifierLength ) ;
2022-07-28 13:39:57 +00:00
for ( size_t i = 0 ; i < identifierLength ; i + + ) {
2021-12-05 17:54:36 +00:00
char16_t character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2021-12-05 17:54:36 +00:00
identifier . push_back ( character ) ;
}
2022-07-17 07:35:11 +00:00
2023-10-21 23:31:55 +00:00
LOG ( " Button: %d; LOT: %u buttonIdentifier: %s; userData: %s " , iButton , entity - > GetLOT ( ) , GeneralUtils : : UTF16ToWTF8 ( buttonIdentifier ) . c_str ( ) , GeneralUtils : : UTF16ToWTF8 ( identifier ) . c_str ( ) ) ;
2021-12-05 17:54:36 +00:00
auto * user = UserManager : : Instance ( ) - > GetUser ( sysAddr ) ;
2022-07-28 13:39:57 +00:00
if ( user = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
auto * userEntity = user - > GetLastUsedChar ( ) - > GetEntity ( ) ;
2022-07-28 13:39:57 +00:00
if ( userEntity = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
entity - > OnChoiceBoxResponse ( userEntity , iButton , buttonIdentifier , identifier ) ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendDisplayZoneSummary ( LWOOBJID objectId , const SystemAddress & sysAddr , bool isPropertyMap , bool isZoneStart , LWOOBJID sender ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : DISPLAY_ZONE_SUMMARY ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( isPropertyMap ) ;
bitStream . Write ( isZoneStart ) ;
bitStream . Write ( sender ! = LWOOBJID_EMPTY ) ;
if ( sender ! = LWOOBJID_EMPTY ) bitStream . Write ( sender ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
//UI
2022-07-28 13:39:57 +00:00
void GameMessages : : SendNotifyNotEnoughInvSpace ( LWOOBJID objectId , uint32_t freeSlotsNeeded , eInventoryType inventoryType , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : VEHICLE_NOTIFY_FINISHED_RACE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( freeSlotsNeeded ) ;
bitStream . Write ( inventoryType ! = 0 ) ;
if ( inventoryType ! = 0 ) bitStream . Write ( inventoryType ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendDisplayMessageBox ( LWOOBJID objectId , bool bShow , LWOOBJID callbackClient , const std : : u16string & identifier , int32_t imageID , const std : : u16string & text , const std : : u16string & userData , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : DISPLAY_MESSAGE_BOX ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bShow ) ;
bitStream . Write ( callbackClient ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( identifier . size ( ) ) ;
2022-07-28 13:39:57 +00:00
for ( const auto character : identifier ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( character ) ;
}
bitStream . Write ( imageID ) ;
2022-07-17 07:35:11 +00:00
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( text . size ( ) ) ;
2022-07-28 13:39:57 +00:00
for ( const auto character : text ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( character ) ;
}
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( userData . size ( ) ) ;
2022-07-28 13:39:57 +00:00
for ( const auto character : userData ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( character ) ;
}
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendDisplayChatBubble ( LWOOBJID objectId , const std : : u16string & text , const SystemAddress & sysAddr ) {
2024-11-18 00:39:44 +00:00
// MessageType::Game::DISPLAY_CHAT_BUBBLE
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : DISPLAY_CHAT_BUBBLE ) ;
2021-12-05 17:54:36 +00:00
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( text . size ( ) ) ;
2022-07-28 13:39:57 +00:00
for ( const auto character : text ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( character ) ;
}
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-12-16 21:24:13 +00:00
2022-12-23 06:14:51 +00:00
void GameMessages : : SendChangeIdleFlags ( LWOOBJID objectId , eAnimationFlags flagsOn , eAnimationFlags flagsOff , const SystemAddress & sysAddr ) {
2022-12-16 21:24:13 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : CHANGE_IDLE_FLAGS ) ;
2022-12-23 06:14:51 +00:00
bitStream . Write < bool > ( flagsOff ! = eAnimationFlags : : IDLE_NONE ) ;
if ( flagsOff ! = eAnimationFlags : : IDLE_NONE ) bitStream . Write ( flagsOff ) ;
bitStream . Write < bool > ( flagsOn ! = eAnimationFlags : : IDLE_NONE ) ;
if ( flagsOn ! = eAnimationFlags : : IDLE_NONE ) bitStream . Write ( flagsOn ) ;
2022-12-16 21:24:13 +00:00
SEND_PACKET_BROADCAST ;
}
2022-07-17 07:35:11 +00:00
// Mounts
2022-07-28 13:39:57 +00:00
void GameMessages : : SendSetMountInventoryID ( Entity * entity , const LWOOBJID & objectID , const SystemAddress & sysAddr ) {
2022-07-17 07:35:11 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_MOUNT_INVENTORY_ID ) ;
2022-07-17 07:35:11 +00:00
bitStream . Write ( objectID ) ;
SEND_PACKET_BROADCAST ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleDismountComplete ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2022-09-02 18:49:19 +00:00
// Get the objectID from the bitstream
2022-07-17 07:35:11 +00:00
LWOOBJID objectId { } ;
2024-02-26 14:17:22 +00:00
inStream . Read ( objectId ) ;
2022-07-17 07:35:11 +00:00
2022-09-02 18:49:19 +00:00
// If we aren't possessing somethings, the don't do anything
2022-07-17 07:35:11 +00:00
if ( objectId ! = LWOOBJID_EMPTY ) {
2022-09-02 18:49:19 +00:00
auto * possessorComponent = entity - > GetComponent < PossessorComponent > ( ) ;
2023-07-15 20:56:33 +00:00
auto * mount = Game : : entityManager - > GetEntity ( objectId ) ;
2022-09-02 18:49:19 +00:00
// make sure we have the things we need and they aren't null
if ( possessorComponent & & mount ) {
if ( ! possessorComponent - > GetIsDismounting ( ) ) return ;
possessorComponent - > SetIsDismounting ( false ) ;
possessorComponent - > SetPossessable ( LWOOBJID_EMPTY ) ;
possessorComponent - > SetPossessableType ( ePossessionType : : NO_POSSESSION ) ;
// character related things
auto * character = entity - > GetComponent < CharacterComponent > ( ) ;
if ( character ) {
// If we had an active item turn it off
if ( possessorComponent - > GetMountItemID ( ) ! = LWOOBJID_EMPTY ) GameMessages : : SendMarkInventoryItemAsActive ( entity - > GetObjectID ( ) , false , eUnequippableActiveType : : MOUNT , possessorComponent - > GetMountItemID ( ) , entity - > GetSystemAddress ( ) ) ;
possessorComponent - > SetMountItemID ( LWOOBJID_EMPTY ) ;
}
2022-07-17 07:35:11 +00:00
2022-09-02 18:49:19 +00:00
// Set that the controllabel phsyics comp is teleporting
auto * controllablePhysicsComponent = entity - > GetComponent < ControllablePhysicsComponent > ( ) ;
if ( controllablePhysicsComponent ) controllablePhysicsComponent - > SetIsTeleporting ( true ) ;
2022-07-17 07:35:11 +00:00
2022-09-02 18:49:19 +00:00
// Call dismoint on the possessable comp to let it handle killing the possessable
auto * possessableComponent = mount - > GetComponent < PossessableComponent > ( ) ;
if ( possessableComponent ) possessableComponent - > Dismount ( ) ;
// Update the entity that was possessing
2023-07-15 20:56:33 +00:00
Game : : entityManager - > SerializeEntity ( entity ) ;
2022-09-02 18:49:19 +00:00
// We aren't mounted so remove the stun
2023-01-07 05:59:19 +00:00
GameMessages : : SendSetStunned ( entity - > GetObjectID ( ) , eStateChangeType : : POP , UNASSIGNED_SYSTEM_ADDRESS , LWOOBJID_EMPTY , true , false , true , false , false , false , false , true , true , true , true , true , true , true , true , true ) ;
2022-07-17 07:35:11 +00:00
}
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleAcknowledgePossession ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2023-07-15 20:56:33 +00:00
Game : : entityManager - > SerializeEntity ( entity ) ;
2022-09-02 18:49:19 +00:00
LWOOBJID objectId { } ;
2024-02-26 14:17:22 +00:00
inStream . Read ( objectId ) ;
2023-07-15 20:56:33 +00:00
auto * mount = Game : : entityManager - > GetEntity ( objectId ) ;
if ( mount ) Game : : entityManager - > SerializeEntity ( mount ) ;
2022-07-17 07:35:11 +00:00
}
2021-12-05 17:54:36 +00:00
//Racing
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleModuleAssemblyQueryData ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
auto * moduleAssemblyComponent = entity - > GetComponent < ModuleAssemblyComponent > ( ) ;
2023-10-21 23:31:55 +00:00
LOG ( " Got Query from %i " , entity - > GetLOT ( ) ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( moduleAssemblyComponent ! = nullptr ) {
2023-10-21 23:31:55 +00:00
LOG ( " Returning assembly %s " , GeneralUtils : : UTF16ToWTF8 ( moduleAssemblyComponent - > GetAssemblyPartsLOTs ( ) ) . c_str ( ) ) ;
2021-12-05 17:54:36 +00:00
2022-07-17 07:35:11 +00:00
SendModuleAssemblyDBDataForClient ( entity - > GetObjectID ( ) , moduleAssemblyComponent - > GetSubKey ( ) , moduleAssemblyComponent - > GetAssemblyPartsLOTs ( ) , UNASSIGNED_SYSTEM_ADDRESS ) ;
2021-12-05 17:54:36 +00:00
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleModularAssemblyNIFCompleted ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
LWOOBJID objectID ;
2024-02-26 14:17:22 +00:00
inStream . Read ( objectID ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleVehicleSetWheelLockState ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
bool bExtraFriction = inStream . ReadBit ( ) ;
bool bLocked = inStream . ReadBit ( ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleRacingClientReady ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
LWOOBJID playerID ;
2024-02-26 14:17:22 +00:00
inStream . Read ( playerID ) ;
2021-12-05 17:54:36 +00:00
2023-07-15 20:56:33 +00:00
auto * player = Game : : entityManager - > GetEntity ( playerID ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( player = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
2023-07-17 22:55:33 +00:00
auto * racingControlComponent = Game : : zoneManager - > GetZoneControlObject ( ) - > GetComponent < RacingControlComponent > ( ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( racingControlComponent = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
racingControlComponent - > OnRacingClientReady ( player ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleRequestDie ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
bool bClientDeath ;
bool bSpawnLoot ;
std : : u16string deathType ;
float directionRelativeAngleXZ ;
float directionRelativeAngleY ;
float directionRelativeForce ;
2023-05-02 22:39:21 +00:00
eKillType killType = eKillType : : VIOLENT ;
2021-12-05 17:54:36 +00:00
LWOOBJID killerID ;
LWOOBJID lootOwnerID = LWOOBJID_EMPTY ;
2024-02-26 14:17:22 +00:00
bClientDeath = inStream . ReadBit ( ) ;
bSpawnLoot = inStream . ReadBit ( ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
uint32_t deathTypeLength = 0 ;
2024-02-26 14:17:22 +00:00
inStream . Read ( deathTypeLength ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
for ( size_t i = 0 ; i < deathTypeLength ; i + + ) {
2021-12-05 17:54:36 +00:00
char16_t character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2021-12-05 17:54:36 +00:00
deathType . push_back ( character ) ;
}
2024-02-26 14:17:22 +00:00
inStream . Read ( directionRelativeAngleXZ ) ;
inStream . Read ( directionRelativeAngleY ) ;
inStream . Read ( directionRelativeForce ) ;
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) {
inStream . Read ( killType ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
inStream . Read ( killerID ) ;
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) {
inStream . Read ( lootOwnerID ) ;
2021-12-05 17:54:36 +00:00
}
2023-07-17 22:55:33 +00:00
auto * zoneController = Game : : zoneManager - > GetZoneControlObject ( ) ;
2021-12-05 17:54:36 +00:00
auto * racingControlComponent = zoneController - > GetComponent < RacingControlComponent > ( ) ;
2023-10-21 23:31:55 +00:00
LOG ( " Got die request: %i " , entity - > GetLOT ( ) ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( racingControlComponent ! = nullptr ) {
2021-12-05 17:54:36 +00:00
auto * possessableComponent = entity - > GetComponent < PossessableComponent > ( ) ;
2022-07-28 13:39:57 +00:00
if ( possessableComponent ! = nullptr ) {
2023-07-15 20:56:33 +00:00
entity = Game : : entityManager - > GetEntity ( possessableComponent - > GetPossessor ( ) ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( entity = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
}
racingControlComponent - > OnRequestDie ( entity ) ;
2023-12-24 00:11:00 +00:00
} else {
2023-11-18 00:43:01 +00:00
auto * destroyableComponent = entity - > GetComponent < DestroyableComponent > ( ) ;
if ( ! destroyableComponent ) return ;
destroyableComponent - > Smash ( killerID , killType , deathType ) ;
}
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleVehicleNotifyServerAddPassiveBoostAction ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
//SendVehicleAddPassiveBoostAction(entity->GetObjectID(), sysAddr);
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleVehicleNotifyServerRemovePassiveBoostAction ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
//SendVehicleRemovePassiveBoostAction(entity->GetObjectID(), sysAddr);
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleRacingPlayerInfoResetFinished ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
LWOOBJID playerID ;
2024-02-26 14:17:22 +00:00
inStream . Read ( playerID ) ;
2021-12-05 17:54:36 +00:00
2023-07-15 20:56:33 +00:00
auto * player = Game : : entityManager - > GetEntity ( playerID ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( player = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
2023-07-17 22:55:33 +00:00
auto * zoneController = Game : : zoneManager - > GetZoneControlObject ( ) ;
2021-12-05 17:54:36 +00:00
auto * racingControlComponent = zoneController - > GetComponent < RacingControlComponent > ( ) ;
2023-10-21 23:31:55 +00:00
LOG ( " Got finished: %i " , entity - > GetLOT ( ) ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( racingControlComponent ! = nullptr ) {
2021-12-05 17:54:36 +00:00
racingControlComponent - > OnRacingPlayerInfoResetFinished ( player ) ;
}
}
2022-03-30 06:46:23 +00:00
void GameMessages : : SendUpdateReputation ( const LWOOBJID objectId , const int64_t reputation , const SystemAddress & sysAddr ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : UPDATE_REPUTATION ) ;
2022-03-30 06:46:23 +00:00
bitStream . Write ( reputation ) ;
SEND_PACKET ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleUpdatePropertyPerformanceCost ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2022-03-30 02:52:07 +00:00
float performanceCost = 0.0f ;
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) inStream . Read ( performanceCost ) ;
2022-03-30 02:52:07 +00:00
if ( performanceCost = = 0.0f ) return ;
2023-07-17 22:55:33 +00:00
auto zone = Game : : zoneManager - > GetZone ( ) ;
2023-11-18 00:47:18 +00:00
if ( ! zone ) {
LOG ( " If you see this message, something is very wrong. " ) ;
return ;
}
2022-03-30 02:52:07 +00:00
2023-11-18 00:47:18 +00:00
Database : : Get ( ) - > UpdatePerformanceCost ( zone - > GetZoneID ( ) , performanceCost ) ;
2022-03-30 02:52:07 +00:00
}
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleVehicleNotifyHitImaginationServer ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
LWOOBJID pickupObjID = LWOOBJID_EMPTY ;
LWOOBJID pickupSpawnerID = LWOOBJID_EMPTY ;
int32_t pickupSpawnerIndex = - 1 ;
2024-01-29 07:53:12 +00:00
NiPoint3 vehiclePosition = NiPoint3Constant : : ZERO ;
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) inStream . Read ( pickupObjID ) ;
if ( inStream . ReadBit ( ) ) inStream . Read ( pickupSpawnerID ) ;
if ( inStream . ReadBit ( ) ) inStream . Read ( pickupSpawnerIndex ) ;
if ( inStream . ReadBit ( ) ) inStream . Read ( vehiclePosition ) ;
2021-12-05 17:54:36 +00:00
2023-07-15 20:56:33 +00:00
auto * pickup = Game : : entityManager - > GetEntity ( pickupObjID ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( pickup = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
auto * possessableComponent = entity - > GetComponent < PossessableComponent > ( ) ;
2022-07-28 13:39:57 +00:00
if ( possessableComponent ! = nullptr ) {
2023-07-15 20:56:33 +00:00
entity = Game : : entityManager - > GetEntity ( possessableComponent - > GetPossessor ( ) ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( entity = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
}
2022-07-23 02:58:20 +00:00
auto * characterComponent = entity - > GetComponent < CharacterComponent > ( ) ;
if ( characterComponent ! = nullptr ) {
characterComponent - > UpdatePlayerStatistic ( RacingImaginationPowerUpsCollected ) ;
}
2021-12-05 17:54:36 +00:00
pickup - > OnFireEventServerSide ( entity , " powerup " ) ;
pickup - > Kill ( entity ) ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendModuleAssemblyDBDataForClient ( LWOOBJID objectId , LWOOBJID assemblyID , const std : : u16string & data , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : MODULE_ASSEMBLY_DB_DATA_FOR_CLIENT ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( assemblyID ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( data . size ( ) ) ;
2022-07-28 13:39:57 +00:00
for ( auto character : data ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( character ) ;
}
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendNotifyVehicleOfRacingObject ( LWOOBJID objectId , LWOOBJID racingObjectID , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : NOTIFY_VEHICLE_OF_RACING_OBJECT ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( racingObjectID ! = LWOOBJID_EMPTY ) ;
if ( racingObjectID ! = LWOOBJID_EMPTY ) bitStream . Write ( racingObjectID ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendRacingPlayerLoaded ( LWOOBJID objectId , LWOOBJID playerID , LWOOBJID vehicleID , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : RACING_PLAYER_LOADED ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( playerID ) ;
bitStream . Write ( vehicleID ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendVehicleUnlockInput ( LWOOBJID objectId , bool bLockWheels , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : VEHICLE_UNLOCK_INPUT ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bLockWheels ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendVehicleSetWheelLockState ( LWOOBJID objectId , bool bExtraFriction , bool bLocked , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : VEHICLE_SET_WHEEL_LOCK_STATE ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bExtraFriction ) ;
bitStream . Write ( bLocked ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendRacingSetPlayerResetInfo ( LWOOBJID objectId , int32_t currentLap , uint32_t furthestResetPlane , LWOOBJID playerID , NiPoint3 respawnPos , uint32_t upcomingPlane , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : RACING_SET_PLAYER_RESET_INFO ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( currentLap ) ;
bitStream . Write ( furthestResetPlane ) ;
bitStream . Write ( playerID ) ;
bitStream . Write ( respawnPos ) ;
bitStream . Write ( upcomingPlane ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendRacingResetPlayerToLastReset ( LWOOBJID objectId , LWOOBJID playerID , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : RACING_RESET_PLAYER_TO_LAST_RESET ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( playerID ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2023-03-05 20:34:59 +00:00
void GameMessages : : SendVehicleStopBoost ( Entity * targetEntity , const SystemAddress & playerSysAddr , bool affectPassive ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( targetEntity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : VEHICLE_STOP_BOOST ) ;
2023-05-02 22:39:21 +00:00
2023-03-05 20:34:59 +00:00
bitStream . Write ( affectPassive ) ;
SEND_PACKET_BROADCAST ;
}
void GameMessages : : SendSetResurrectRestoreValues ( Entity * targetEntity , int32_t armorRestore , int32_t healthRestore , int32_t imaginationRestore ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( targetEntity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_RESURRECT_RESTORE_VALUES ) ;
2023-05-02 22:39:21 +00:00
2023-03-05 20:34:59 +00:00
bitStream . Write ( armorRestore ! = - 1 ) ;
if ( armorRestore ! = - 1 ) bitStream . Write ( armorRestore ) ;
bitStream . Write ( healthRestore ! = - 1 ) ;
if ( healthRestore ! = - 1 ) bitStream . Write ( healthRestore ) ;
bitStream . Write ( imaginationRestore ! = - 1 ) ;
if ( imaginationRestore ! = - 1 ) bitStream . Write ( imaginationRestore ) ;
SEND_PACKET_BROADCAST ;
}
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
void GameMessages : : SendNotifyRacingClient ( LWOOBJID objectId , int32_t eventType , int32_t param1 , LWOOBJID paramObj , std : : u16string paramStr , LWOOBJID singleClient , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : NOTIFY_RACING_CLIENT ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( eventType ! = 0 ) ;
if ( eventType ! = 0 ) bitStream . Write ( eventType ) ;
bitStream . Write ( param1 ) ;
bitStream . Write ( paramObj ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( paramStr . size ( ) ) ;
2022-07-28 13:39:57 +00:00
for ( auto character : paramStr ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( character ) ;
}
bitStream . Write ( singleClient ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendActivityEnter ( LWOOBJID objectId , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : ACTIVITY_ENTER ) ;
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendActivityStart ( LWOOBJID objectId , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : ACTIVITY_START ) ;
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendActivityExit ( LWOOBJID objectId , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : ACTIVITY_EXIT ) ;
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendActivityStop ( LWOOBJID objectId , bool bExit , bool bUserCancel , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : ACTIVITY_STOP ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bExit ) ;
bitStream . Write ( bUserCancel ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendVehicleAddPassiveBoostAction ( LWOOBJID objectId , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : VEHICLE_ADD_PASSIVE_BOOST_ACTION ) ;
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendVehicleRemovePassiveBoostAction ( LWOOBJID objectId , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : VEHICLE_REMOVE_PASSIVE_BOOST_ACTION ) ;
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2022-07-28 13:39:57 +00:00
void GameMessages : : SendVehicleNotifyFinishedRace ( LWOOBJID objectId , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : VEHICLE_NOTIFY_FINISHED_RACE ) ;
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
void GameMessages : : SendAddBuff ( LWOOBJID & objectID , const LWOOBJID & casterID , uint32_t buffID , uint32_t msDuration ,
2022-07-28 13:39:57 +00:00
bool addImmunity , bool cancelOnDamaged , bool cancelOnDeath , bool cancelOnLogout ,
2023-12-01 16:12:48 +00:00
bool cancelOnRemoveBuff , bool cancelOnUi , bool cancelOnUnequip , bool cancelOnZone , bool addedByTeammate , bool applyOnTeammates ,
2022-07-28 13:39:57 +00:00
const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectID ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : ADD_BUFF ) ;
2021-12-05 17:54:36 +00:00
2023-12-01 16:12:48 +00:00
bitStream . Write ( addedByTeammate ) ; // Added by teammate
bitStream . Write ( applyOnTeammates ) ; // Apply on teammates
2021-12-05 17:54:36 +00:00
bitStream . Write ( cancelOnDamaged ) ;
bitStream . Write ( cancelOnDeath ) ;
bitStream . Write ( cancelOnLogout ) ;
2023-12-01 16:12:48 +00:00
2021-12-05 17:54:36 +00:00
bitStream . Write ( false ) ; // Cancel on move
bitStream . Write ( cancelOnRemoveBuff ) ;
bitStream . Write ( cancelOnUi ) ;
bitStream . Write ( cancelOnUnequip ) ;
bitStream . Write ( cancelOnZone ) ;
2023-12-01 16:12:48 +00:00
2021-12-05 17:54:36 +00:00
bitStream . Write ( false ) ; // Ignore immunities
bitStream . Write ( addImmunity ) ;
bitStream . Write ( false ) ; // Use ref count
2023-12-01 16:12:48 +00:00
bitStream . Write ( casterID ! = LWOOBJID_EMPTY ) ;
if ( casterID ! = LWOOBJID_EMPTY ) bitStream . Write ( casterID ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( buffID ) ;
2023-12-01 16:12:48 +00:00
bitStream . Write ( msDuration ! = 0 ) ;
if ( msDuration ! = 0 ) bitStream . Write ( msDuration ) ;
2021-12-05 17:54:36 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
// NT
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleRequestMoveItemBetweenInventoryTypes ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2022-12-04 22:25:25 +00:00
bool bAllowPartial { } ;
2021-12-05 17:54:36 +00:00
int32_t destSlot = - 1 ;
int32_t iStackCount = 1 ;
eInventoryType invTypeDst = ITEMS ;
eInventoryType invTypeSrc = ITEMS ;
LWOOBJID itemID = LWOOBJID_EMPTY ;
2022-12-04 22:25:25 +00:00
bool showFlyingLoot { } ;
2021-12-05 17:54:36 +00:00
LWOOBJID subkey = LWOOBJID_EMPTY ;
LOT itemLOT = 0 ;
2024-02-26 14:17:22 +00:00
bAllowPartial = inStream . ReadBit ( ) ;
if ( inStream . ReadBit ( ) ) inStream . Read ( destSlot ) ;
if ( inStream . ReadBit ( ) ) inStream . Read ( iStackCount ) ;
if ( inStream . ReadBit ( ) ) inStream . Read ( invTypeDst ) ;
if ( inStream . ReadBit ( ) ) inStream . Read ( invTypeSrc ) ;
if ( inStream . ReadBit ( ) ) inStream . Read ( itemID ) ;
showFlyingLoot = inStream . ReadBit ( ) ;
if ( inStream . ReadBit ( ) ) inStream . Read ( subkey ) ;
if ( inStream . ReadBit ( ) ) inStream . Read ( itemLOT ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( invTypeDst = = invTypeSrc ) {
2024-05-25 02:35:14 +00:00
SendResponseMoveItemBetweenInventoryTypes ( entity - > GetObjectID ( ) , sysAddr , invTypeDst , invTypeSrc , eReponseMoveItemBetweenInventoryTypeCode : : FAIL_GENERIC ) ;
2021-12-05 17:54:36 +00:00
return ;
}
auto * inventoryComponent = entity - > GetComponent < InventoryComponent > ( ) ;
2024-05-25 02:35:14 +00:00
if ( inventoryComponent ) {
2022-07-28 13:39:57 +00:00
if ( itemID ! = LWOOBJID_EMPTY ) {
2021-12-05 17:54:36 +00:00
auto * item = inventoryComponent - > FindItemById ( itemID ) ;
2024-05-25 02:35:14 +00:00
if ( ! item ) {
SendResponseMoveItemBetweenInventoryTypes ( entity - > GetObjectID ( ) , sysAddr , invTypeDst , invTypeSrc , eReponseMoveItemBetweenInventoryTypeCode : : FAIL_ITEM_NOT_FOUND ) ;
return ;
2024-11-18 00:39:44 +00:00
}
2024-05-25 02:35:14 +00:00
if ( item - > GetLot ( ) = = 6086 ) { // Thinking hat
SendResponseMoveItemBetweenInventoryTypes ( entity - > GetObjectID ( ) , sysAddr , invTypeDst , invTypeSrc , eReponseMoveItemBetweenInventoryTypeCode : : FAIL_CANT_MOVE_THINKING_HAT ) ;
return ;
}
2024-11-18 00:39:44 +00:00
2024-05-25 02:35:14 +00:00
auto * destInv = inventoryComponent - > GetInventory ( invTypeDst ) ;
if ( destInv & & destInv - > GetEmptySlots ( ) = = 0 ) {
SendResponseMoveItemBetweenInventoryTypes ( entity - > GetObjectID ( ) , sysAddr , invTypeDst , invTypeSrc , eReponseMoveItemBetweenInventoryTypeCode : : FAIL_INV_FULL ) ;
return ;
}
2021-12-05 17:54:36 +00:00
2022-12-04 22:25:25 +00:00
// Despawn the pet if we are moving that pet to the vault.
auto * petComponent = PetComponent : : GetActivePet ( entity - > GetObjectID ( ) ) ;
if ( petComponent & & petComponent - > GetDatabaseId ( ) = = item - > GetSubKey ( ) ) {
inventoryComponent - > DespawnPet ( ) ;
2021-12-05 17:54:36 +00:00
}
inventoryComponent - > MoveItemToInventory ( item , invTypeDst , iStackCount , showFlyingLoot , false , false , destSlot ) ;
2024-05-25 02:35:14 +00:00
SendResponseMoveItemBetweenInventoryTypes ( entity - > GetObjectID ( ) , sysAddr , invTypeDst , invTypeSrc , eReponseMoveItemBetweenInventoryTypeCode : : SUCCESS ) ;
2021-12-05 17:54:36 +00:00
}
2024-05-25 02:35:14 +00:00
} else {
SendResponseMoveItemBetweenInventoryTypes ( entity - > GetObjectID ( ) , sysAddr , invTypeDst , invTypeSrc , eReponseMoveItemBetweenInventoryTypeCode : : FAIL_GENERIC ) ;
2021-12-05 17:54:36 +00:00
}
}
2024-05-25 02:35:14 +00:00
void GameMessages : : SendResponseMoveItemBetweenInventoryTypes ( LWOOBJID objectId , const SystemAddress & sysAddr , eInventoryType inventoryTypeDestination , eInventoryType inventoryTypeSource , eReponseMoveItemBetweenInventoryTypeCode response ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : RESPONSE_MOVE_ITEM_BETWEEN_INVENTORY_TYPES ) ;
2024-05-25 02:35:14 +00:00
bitStream . Write ( inventoryTypeDestination ! = eInventoryType : : ITEMS ) ;
if ( inventoryTypeDestination ! = eInventoryType : : ITEMS ) bitStream . Write ( inventoryTypeDestination ) ;
bitStream . Write ( inventoryTypeSource ! = eInventoryType : : ITEMS ) ;
if ( inventoryTypeSource ! = eInventoryType : : ITEMS ) bitStream . Write ( inventoryTypeSource ) ;
bitStream . Write ( response ! = eReponseMoveItemBetweenInventoryTypeCode : : FAIL_GENERIC ) ;
if ( response ! = eReponseMoveItemBetweenInventoryTypeCode : : FAIL_GENERIC ) bitStream . Write ( response ) ;
SEND_PACKET ;
}
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
void GameMessages : : SendShowActivityCountdown ( LWOOBJID objectId , bool bPlayAdditionalSound , bool bPlayCountdownSound , std : : u16string sndName , int32_t stateToPlaySoundOn , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SHOW_ACTIVITY_COUNTDOWN ) ;
2021-12-05 17:54:36 +00:00
bitStream . Write ( bPlayAdditionalSound ) ;
bitStream . Write ( bPlayCountdownSound ) ;
2023-12-24 00:11:00 +00:00
bitStream . Write < uint32_t > ( sndName . size ( ) ) ;
2022-07-28 13:39:57 +00:00
for ( auto character : sndName ) {
2021-12-05 17:54:36 +00:00
bitStream . Write ( character ) ;
}
bitStream . Write ( stateToPlaySoundOn ) ;
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
//-----------------------------------------------------------------------------------------------------------------------------------------------
//------------------------------------------------------------------- Handlers ------------------------------------------------------------------
//-----------------------------------------------------------------------------------------------------------------------------------------------
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleToggleGhostReferenceOverride ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
bool bOverride = false ;
2024-02-26 14:17:22 +00:00
inStream . Read ( bOverride ) ;
2021-12-05 17:54:36 +00:00
2024-01-13 09:40:56 +00:00
auto * player = PlayerManager : : GetPlayer ( sysAddr ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( player ! = nullptr ) {
2024-01-14 19:10:13 +00:00
auto * ghostComponent = entity - > GetComponent < GhostComponent > ( ) ;
if ( ghostComponent ) ghostComponent - > SetGhostOverride ( bOverride ) ;
2022-07-17 07:35:11 +00:00
2023-07-15 20:56:33 +00:00
Game : : entityManager - > UpdateGhosting ( player ) ;
2021-12-05 17:54:36 +00:00
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleSetGhostReferencePosition ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
NiPoint3 position ;
2024-02-26 14:17:22 +00:00
inStream . Read ( position ) ;
2021-12-05 17:54:36 +00:00
2024-01-13 09:40:56 +00:00
auto * player = PlayerManager : : GetPlayer ( sysAddr ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( player ! = nullptr ) {
2024-01-14 19:10:13 +00:00
auto * ghostComponent = entity - > GetComponent < GhostComponent > ( ) ;
if ( ghostComponent ) ghostComponent - > SetGhostOverridePoint ( position ) ;
2021-12-05 17:54:36 +00:00
2023-07-15 20:56:33 +00:00
Game : : entityManager - > UpdateGhosting ( player ) ;
2021-12-05 17:54:36 +00:00
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleBuyFromVendor ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2024-01-11 04:57:41 +00:00
bool bConfirmed { } ; // This doesn't appear to do anything. Further research is needed.
2021-12-05 17:54:36 +00:00
bool countIsDefault { } ;
int count = 1 ;
LOT item ;
2024-02-26 14:17:22 +00:00
inStream . Read ( bConfirmed ) ;
inStream . Read ( countIsDefault ) ;
if ( countIsDefault ) inStream . Read ( count ) ;
inStream . Read ( item ) ;
2021-12-05 17:54:36 +00:00
User * user = UserManager : : Instance ( ) - > GetUser ( sysAddr ) ;
if ( ! user ) return ;
2023-07-15 20:56:33 +00:00
Entity * player = Game : : entityManager - > GetEntity ( user - > GetLoggedInChar ( ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! player ) return ;
2024-04-09 04:50:41 +00:00
2024-02-25 07:47:05 +00:00
// handle buying normal items
auto * vendorComponent = entity - > GetComponent < VendorComponent > ( ) ;
if ( vendorComponent ) {
vendorComponent - > Buy ( player , item , count ) ;
2021-12-05 17:54:36 +00:00
return ;
}
2024-02-25 07:47:05 +00:00
// handle buying achievement items
auto * achievementVendorComponent = entity - > GetComponent < AchievementVendorComponent > ( ) ;
if ( achievementVendorComponent ) {
achievementVendorComponent - > Buy ( player , item , count ) ;
2023-06-03 07:40:46 +00:00
return ;
}
2024-02-25 07:47:05 +00:00
// Handle buying properties
auto * propertyVendorComponent = entity - > GetComponent < PropertyVendorComponent > ( ) ;
if ( propertyVendorComponent ) {
propertyVendorComponent - > OnBuyFromVendor ( player , bConfirmed , item , count ) ;
return ;
2021-12-05 17:54:36 +00:00
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleSellToVendor ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
bool countIsDefault { } ;
int count = 1 ;
LWOOBJID iObjID ;
2024-02-26 14:17:22 +00:00
inStream . Read ( countIsDefault ) ;
if ( countIsDefault ) inStream . Read ( count ) ;
inStream . Read ( iObjID ) ;
2021-12-05 17:54:36 +00:00
User * user = UserManager : : Instance ( ) - > GetUser ( sysAddr ) ;
if ( ! user ) return ;
2023-07-15 20:56:33 +00:00
Entity * player = Game : : entityManager - > GetEntity ( user - > GetLoggedInChar ( ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! player ) return ;
Character * character = player - > GetCharacter ( ) ;
if ( ! character ) return ;
2023-03-04 07:16:37 +00:00
InventoryComponent * inv = static_cast < InventoryComponent * > ( player - > GetComponent ( eReplicaComponentType : : INVENTORY ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! inv ) return ;
2023-03-04 07:16:37 +00:00
VendorComponent * vend = static_cast < VendorComponent * > ( entity - > GetComponent ( eReplicaComponentType : : VENDOR ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! vend ) return ;
Item * item = inv - > FindItemById ( iObjID ) ;
if ( ! item ) return ;
2024-02-09 05:40:43 +00:00
CDComponentsRegistryTable * compRegistryTable = CDClientManager : : GetTable < CDComponentsRegistryTable > ( ) ;
CDItemComponentTable * itemComponentTable = CDClientManager : : GetTable < CDItemComponentTable > ( ) ;
2021-12-05 17:54:36 +00:00
2023-03-04 07:16:37 +00:00
int itemCompID = compRegistryTable - > GetByIDAndType ( item - > GetLot ( ) , eReplicaComponentType : : ITEM ) ;
2021-12-05 17:54:36 +00:00
CDItemComponent itemComp = itemComponentTable - > GetItemComponentByID ( itemCompID ) ;
// Items with a base value of 0 or max int are special items that should not be sold if they're not sub items
2024-02-25 07:47:05 +00:00
if ( itemComp . baseValue = = 0 | | itemComp . baseValue = = UINT_MAX ) {
GameMessages : : SendVendorTransactionResult ( entity , sysAddr , eVendorTransactionResult : : SELL_FAIL ) ;
return ;
}
2021-12-05 17:54:36 +00:00
float sellScalar = vend - > GetSellScalar ( ) ;
2022-07-28 13:39:57 +00:00
if ( Inventory : : IsValidItem ( itemComp . currencyLOT ) ) {
2022-12-24 08:51:59 +00:00
const auto altCurrency = static_cast < uint32_t > ( itemComp . altCurrencyCost * sellScalar ) * count ;
2023-05-02 22:39:21 +00:00
inv - > AddItem ( itemComp . currencyLOT , std : : floor ( altCurrency ) , eLootSourceType : : VENDOR ) ; // Return alt currencies like faction tokens.
2021-12-05 17:54:36 +00:00
}
2022-04-24 03:32:31 +00:00
inv - > MoveItemToInventory ( item , eInventoryType : : VENDOR_BUYBACK , count , true , false , true ) ;
2023-05-02 22:39:21 +00:00
character - > SetCoins ( std : : floor ( character - > GetCoins ( ) + ( static_cast < uint32_t > ( itemComp . baseValue * sellScalar ) * count ) ) , eLootSourceType : : VENDOR ) ;
2024-02-25 07:47:05 +00:00
GameMessages : : SendVendorTransactionResult ( entity , sysAddr , eVendorTransactionResult : : SELL_SUCCESS ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleBuybackFromVendor ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
bool confirmed = false ;
bool countIsDefault { } ;
int count = 1 ;
LWOOBJID iObjID ;
2024-02-26 14:17:22 +00:00
inStream . Read ( confirmed ) ;
inStream . Read ( countIsDefault ) ;
if ( countIsDefault ) inStream . Read ( count ) ;
inStream . Read ( iObjID ) ;
2021-12-05 17:54:36 +00:00
//if (!confirmed) return; they always built in this confirmed garbage... but never used it?
User * user = UserManager : : Instance ( ) - > GetUser ( sysAddr ) ;
if ( ! user ) return ;
2023-07-15 20:56:33 +00:00
Entity * player = Game : : entityManager - > GetEntity ( user - > GetLoggedInChar ( ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! player ) return ;
Character * character = player - > GetCharacter ( ) ;
if ( ! character ) return ;
2023-03-04 07:16:37 +00:00
InventoryComponent * inv = static_cast < InventoryComponent * > ( player - > GetComponent ( eReplicaComponentType : : INVENTORY ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! inv ) return ;
2023-03-04 07:16:37 +00:00
VendorComponent * vend = static_cast < VendorComponent * > ( entity - > GetComponent ( eReplicaComponentType : : VENDOR ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! vend ) return ;
Item * item = inv - > FindItemById ( iObjID ) ;
if ( ! item ) return ;
2024-02-09 05:40:43 +00:00
CDComponentsRegistryTable * compRegistryTable = CDClientManager : : GetTable < CDComponentsRegistryTable > ( ) ;
CDItemComponentTable * itemComponentTable = CDClientManager : : GetTable < CDItemComponentTable > ( ) ;
2021-12-05 17:54:36 +00:00
2023-03-04 07:16:37 +00:00
int itemCompID = compRegistryTable - > GetByIDAndType ( item - > GetLot ( ) , eReplicaComponentType : : ITEM ) ;
2021-12-05 17:54:36 +00:00
CDItemComponent itemComp = itemComponentTable - > GetItemComponentByID ( itemCompID ) ;
float sellScalar = vend - > GetSellScalar ( ) ;
const auto cost = static_cast < uint32_t > ( std : : floor ( ( ( itemComp . baseValue * sellScalar ) * count ) ) ) ;
2022-07-28 13:39:57 +00:00
if ( character - > GetCoins ( ) < cost ) {
2024-02-25 07:47:05 +00:00
GameMessages : : SendVendorTransactionResult ( entity , sysAddr , eVendorTransactionResult : : PURCHASE_FAIL ) ;
2021-12-05 17:54:36 +00:00
return ;
}
2022-07-28 13:39:57 +00:00
if ( Inventory : : IsValidItem ( itemComp . currencyLOT ) ) {
2021-12-05 17:54:36 +00:00
const uint32_t altCurrencyCost = std : : floor ( itemComp . altCurrencyCost * sellScalar ) * count ;
2022-07-28 13:39:57 +00:00
if ( inv - > GetLotCount ( itemComp . currencyLOT ) < altCurrencyCost ) {
2024-02-25 07:47:05 +00:00
GameMessages : : SendVendorTransactionResult ( entity , sysAddr , eVendorTransactionResult : : PURCHASE_FAIL ) ;
2021-12-05 17:54:36 +00:00
return ;
}
inv - > RemoveItem ( itemComp . currencyLOT , altCurrencyCost ) ;
}
//inv->RemoveItem(count, -1, iObjID);
inv - > MoveItemToInventory ( item , Inventory : : FindInventoryTypeForLot ( item - > GetLot ( ) ) , count , true , false ) ;
2023-05-02 22:39:21 +00:00
character - > SetCoins ( character - > GetCoins ( ) - cost , eLootSourceType : : VENDOR ) ;
2023-07-15 20:56:33 +00:00
//Game::entityManager->SerializeEntity(player); // so inventory updates
2024-02-25 07:47:05 +00:00
GameMessages : : SendVendorTransactionResult ( entity , sysAddr , eVendorTransactionResult : : PURCHASE_SUCCESS ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleParseChatMessage ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
std : : u16string wsString ;
int iClientState ;
2024-02-26 14:17:22 +00:00
inStream . Read ( iClientState ) ;
2021-12-05 17:54:36 +00:00
uint32_t wsStringLength ;
2024-02-26 14:17:22 +00:00
inStream . Read ( wsStringLength ) ;
2021-12-05 17:54:36 +00:00
for ( uint32_t i = 0 ; i < wsStringLength ; + + i ) {
uint16_t character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2021-12-05 17:54:36 +00:00
wsString . push_back ( character ) ;
}
if ( wsString [ 0 ] = = L ' / ' ) {
SlashCommandHandler : : HandleChatCommand ( wsString , entity , sysAddr ) ;
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleFireEventServerSide ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
uint32_t argsLength { } ;
std : : u16string args { } ;
bool param1IsDefault { } ;
int param1 = - 1 ;
bool param2IsDefault { } ;
int param2 = - 1 ;
bool param3IsDefault { } ;
int param3 = - 1 ;
LWOOBJID senderID { } ;
2024-02-26 14:17:22 +00:00
inStream . Read ( argsLength ) ;
2021-12-05 17:54:36 +00:00
for ( uint32_t i = 0 ; i < argsLength ; + + i ) {
uint16_t character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2021-12-05 17:54:36 +00:00
args . push_back ( character ) ;
}
2024-02-26 14:17:22 +00:00
inStream . Read ( param1IsDefault ) ;
if ( param1IsDefault ) inStream . Read ( param1 ) ;
inStream . Read ( param2IsDefault ) ;
if ( param2IsDefault ) inStream . Read ( param2 ) ;
inStream . Read ( param3IsDefault ) ;
if ( param3IsDefault ) inStream . Read ( param3 ) ;
inStream . Read ( senderID ) ;
2021-12-05 17:54:36 +00:00
2023-07-15 20:56:33 +00:00
auto * sender = Game : : entityManager - > GetEntity ( senderID ) ;
2024-01-13 09:40:56 +00:00
auto * player = PlayerManager : : GetPlayer ( sysAddr ) ;
2021-12-05 17:54:36 +00:00
if ( ! player ) {
return ;
}
// This should probably get it's own "ServerEvents" system or something at some point
if ( args = = u " ZonePlayer " ) {
// Should probably check to make sure they're using a launcher at some point before someone makes a hack that lets you testmap
LWOCLONEID cloneId = 0 ;
LWOMAPID mapId = 0 ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
auto * rocketPad = entity - > GetComponent < RocketLaunchpadControlComponent > ( ) ;
if ( rocketPad = = nullptr ) return ;
cloneId = rocketPad - > GetSelectedCloneId ( player - > GetObjectID ( ) ) ;
if ( param2 ) {
mapId = rocketPad - > GetDefaultZone ( ) ;
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
mapId = param3 ;
}
2022-07-28 13:39:57 +00:00
if ( mapId = = 0 ) {
2021-12-05 17:54:36 +00:00
mapId = rocketPad - > GetSelectedMapId ( player - > GetObjectID ( ) ) ;
}
2022-07-28 13:39:57 +00:00
if ( mapId = = 0 ) {
2023-07-17 22:55:33 +00:00
mapId = Game : : zoneManager - > GetZoneID ( ) . GetMapID ( ) ; // Fallback to sending the player back to the same zone.
2021-12-05 17:54:36 +00:00
}
2023-12-28 04:18:20 +00:00
LOG ( " Player %llu has requested zone transfer to (%i, %i). " , sender - > GetObjectID ( ) , static_cast < int > ( mapId ) , static_cast < int > ( cloneId ) ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
auto * character = player - > GetCharacter ( ) ;
if ( mapId < = 0 ) {
return ;
}
ZoneInstanceManager : : Instance ( ) - > RequestZoneTransfer ( Game : : server , mapId , cloneId , false , [ = ] ( bool mythranShift , uint32_t zoneID , uint32_t zoneInstance , uint32_t zoneClone , std : : string serverIP , uint16_t serverPort ) {
2023-10-21 23:31:55 +00:00
LOG ( " Transferring %s to Zone %i (Instance %i | Clone %i | Mythran Shift: %s) with IP %s and Port %i " , character - > GetName ( ) . c_str ( ) , zoneID , zoneInstance , zoneClone , mythranShift = = true ? " true " : " false " , serverIP . c_str ( ) , serverPort ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
if ( character ) {
character - > SetZoneID ( zoneID ) ;
character - > SetZoneInstance ( zoneInstance ) ;
character - > SetZoneClone ( zoneClone ) ;
}
WorldPackets : : SendTransferToWorld ( sysAddr , serverIP , serverPort , mythranShift ) ;
return ;
2022-07-28 13:39:57 +00:00
} ) ;
2021-12-05 17:54:36 +00:00
}
2022-07-23 02:58:20 +00:00
entity - > OnFireEventServerSide ( sender , GeneralUtils : : UTF16ToWTF8 ( args ) , param1 , param2 , param3 ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleRequestPlatformResync ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
if ( entity - > GetLOT ( ) = = 6267 | | entity - > GetLOT ( ) = = 16141 ) return ;
GameMessages : : SendPlatformResync ( entity , sysAddr ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleQuickBuildCancel ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
bool bEarlyRelease ;
LWOOBJID userID ;
2024-02-26 14:17:22 +00:00
inStream . Read ( bEarlyRelease ) ;
inStream . Read ( userID ) ;
2021-12-05 17:54:36 +00:00
2023-12-29 04:24:30 +00:00
auto * quickBuildComponent = static_cast < QuickBuildComponent * > ( entity - > GetComponent ( eReplicaComponentType : : QUICK_BUILD ) ) ; ;
if ( ! quickBuildComponent ) return ;
2021-12-05 17:54:36 +00:00
2023-12-29 04:24:30 +00:00
quickBuildComponent - > CancelQuickBuild ( Game : : entityManager - > GetEntity ( userID ) , eQuickBuildFailReason : : CANCELED_EARLY ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleRequestUse ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
bool bIsMultiInteractUse = false ;
unsigned int multiInteractID ;
int multiInteractType ;
bool secondary ;
LWOOBJID objectID ;
2024-02-26 14:17:22 +00:00
inStream . Read ( bIsMultiInteractUse ) ;
inStream . Read ( multiInteractID ) ;
inStream . Read ( multiInteractType ) ;
inStream . Read ( objectID ) ;
inStream . Read ( secondary ) ;
2021-12-05 17:54:36 +00:00
2023-07-15 20:56:33 +00:00
Entity * interactedObject = Game : : entityManager - > GetEntity ( objectID ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( interactedObject = = nullptr ) {
2023-10-21 23:31:55 +00:00
LOG ( " Object %llu tried to interact, but doesn't exist! " , objectID ) ;
2021-12-05 17:54:36 +00:00
return ;
}
2022-07-17 07:35:11 +00:00
2022-07-28 13:39:57 +00:00
if ( interactedObject - > GetLOT ( ) = = 9524 ) {
2021-12-05 17:54:36 +00:00
entity - > GetCharacter ( ) - > SetBuildMode ( true ) ;
}
2022-07-17 07:35:11 +00:00
2022-07-28 13:39:57 +00:00
if ( bIsMultiInteractUse ) {
if ( multiInteractType = = 0 ) {
2023-03-04 07:16:37 +00:00
auto * missionOfferComponent = static_cast < MissionOfferComponent * > ( interactedObject - > GetComponent ( eReplicaComponentType : : MISSION_OFFER ) ) ;
2021-12-05 17:54:36 +00:00
2022-07-28 13:39:57 +00:00
if ( missionOfferComponent ! = nullptr ) {
2021-12-05 17:54:36 +00:00
missionOfferComponent - > OfferMissions ( entity , multiInteractID ) ;
}
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
interactedObject - > OnUse ( entity ) ;
}
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
interactedObject - > OnUse ( entity ) ;
}
//Perform use task if possible:
2023-03-04 07:16:37 +00:00
auto missionComponent = static_cast < MissionComponent * > ( entity - > GetComponent ( eReplicaComponentType : : MISSION ) ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
if ( missionComponent = = nullptr ) return ;
2023-01-22 23:38:47 +00:00
missionComponent - > Progress ( eMissionTaskType : : TALK_TO_NPC , interactedObject - > GetLOT ( ) , interactedObject - > GetObjectID ( ) ) ;
missionComponent - > Progress ( eMissionTaskType : : INTERACT , interactedObject - > GetLOT ( ) , interactedObject - > GetObjectID ( ) ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandlePlayEmote ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
int emoteID ;
LWOOBJID targetID ;
2024-02-26 14:17:22 +00:00
inStream . Read ( emoteID ) ;
inStream . Read ( targetID ) ;
2021-12-05 17:54:36 +00:00
2023-10-21 23:31:55 +00:00
LOG_DEBUG ( " Emote (%i) (%llu) " , emoteID , targetID ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
//TODO: If targetID != 0, and we have one of the "perform emote" missions, complete them.
if ( emoteID = = 0 ) return ;
std : : string sAnimationName = " deaded " ; //Default name in case we fail to get the emote
2024-02-09 05:40:43 +00:00
CDEmoteTableTable * emotes = CDClientManager : : GetTable < CDEmoteTableTable > ( ) ;
2023-11-22 14:06:09 +00:00
if ( emotes ) {
CDEmoteTable * emote = emotes - > GetEmote ( emoteID ) ;
if ( emote ) sAnimationName = emote - > animationName ;
}
RenderComponent : : PlayAnimation ( entity , sAnimationName ) ;
2022-11-27 12:03:30 +00:00
MissionComponent * missionComponent = entity - > GetComponent < MissionComponent > ( ) ;
if ( ! missionComponent ) return ;
2022-07-17 07:35:11 +00:00
2022-07-28 13:39:57 +00:00
if ( targetID ! = LWOOBJID_EMPTY ) {
2023-07-15 20:56:33 +00:00
auto * targetEntity = Game : : entityManager - > GetEntity ( targetID ) ;
2021-12-05 17:54:36 +00:00
2023-10-21 23:31:55 +00:00
LOG_DEBUG ( " Emote target found (%d) " , targetEntity ! = nullptr ) ;
2022-07-17 07:35:11 +00:00
2022-07-28 13:39:57 +00:00
if ( targetEntity ! = nullptr ) {
2021-12-05 17:54:36 +00:00
targetEntity - > OnEmoteReceived ( emoteID , entity ) ;
2023-01-22 23:38:47 +00:00
missionComponent - > Progress ( eMissionTaskType : : EMOTE , emoteID , targetID ) ;
2021-12-05 17:54:36 +00:00
}
2022-07-28 13:39:57 +00:00
} else {
2023-10-21 23:31:55 +00:00
LOG_DEBUG ( " Target ID is empty, using backup " ) ;
2023-07-15 20:56:33 +00:00
const auto scriptedEntities = Game : : entityManager - > GetEntitiesByComponent ( eReplicaComponentType : : SCRIPT ) ;
2021-12-05 17:54:36 +00:00
const auto & referencePoint = entity - > GetPosition ( ) ;
2022-07-28 13:39:57 +00:00
for ( auto * scripted : scriptedEntities ) {
2021-12-05 17:54:36 +00:00
if ( Vector3 : : DistanceSquared ( scripted - > GetPosition ( ) , referencePoint ) > 5.0f * 5.0f ) continue ;
scripted - > OnEmoteReceived ( emoteID , entity ) ;
2023-01-22 23:38:47 +00:00
missionComponent - > Progress ( eMissionTaskType : : EMOTE , emoteID , scripted - > GetObjectID ( ) ) ;
2021-12-05 17:54:36 +00:00
}
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleModularBuildConvertModel ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
LWOOBJID modelID ;
2024-02-26 14:17:22 +00:00
inStream . Read ( modelID ) ;
2021-12-05 17:54:36 +00:00
User * user = UserManager : : Instance ( ) - > GetUser ( sysAddr ) ;
if ( ! user ) return ;
2023-07-15 20:56:33 +00:00
Entity * character = Game : : entityManager - > GetEntity ( user - > GetLoggedInChar ( ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! character ) return ;
2023-03-04 07:16:37 +00:00
InventoryComponent * inv = static_cast < InventoryComponent * > ( character - > GetComponent ( eReplicaComponentType : : INVENTORY ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! inv ) return ;
auto * item = inv - > FindItemById ( modelID ) ;
2022-07-28 13:39:57 +00:00
if ( item = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
item - > Disassemble ( TEMP_MODELS ) ;
2024-12-06 04:00:54 +00:00
Database : : Get ( ) - > DeleteUgcBuild ( item - > GetSubKey ( ) ) ;
2023-11-16 01:32:30 +00:00
2023-05-02 22:39:21 +00:00
item - > SetCount ( item - > GetCount ( ) - 1 , false , false , true , eLootSourceType : : QUICKBUILD ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleSetFlag ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
bool bFlag { } ;
2023-05-02 22:39:21 +00:00
int32_t iFlagID { } ;
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
inStream . Read ( bFlag ) ;
inStream . Read ( iFlagID ) ;
2021-12-05 17:54:36 +00:00
2024-02-04 14:29:05 +00:00
auto character = entity - > GetCharacter ( ) ;
if ( character ) character - > SetPlayerFlag ( iFlagID , bFlag ) ;
2024-12-11 03:10:54 +00:00
// This is always set the first time a player loads into a world from character select
// and is used to know when to refresh the players inventory items so they show up.
if ( iFlagID = = ePlayerFlag : : IS_NEWS_SCREEN_VISIBLE & & bFlag ) {
entity - > SetVar < bool > ( u " dlu_first_time_load " , true ) ;
}
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleRespondToMission ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
int missionID { } ;
LWOOBJID playerID { } ;
LWOOBJID receiverID { } ;
bool isDefaultReward { } ;
LOT reward = LOT_NULL ;
2024-02-26 14:17:22 +00:00
inStream . Read ( missionID ) ;
inStream . Read ( playerID ) ;
inStream . Read ( receiverID ) ;
inStream . Read ( isDefaultReward ) ;
if ( isDefaultReward ) inStream . Read ( reward ) ;
2021-12-05 17:54:36 +00:00
2023-03-04 07:16:37 +00:00
MissionComponent * missionComponent = static_cast < MissionComponent * > ( entity - > GetComponent ( eReplicaComponentType : : MISSION ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! missionComponent ) {
2023-10-21 23:31:55 +00:00
LOG ( " Unable to get mission component for entity %llu to handle RespondToMission " , playerID ) ;
2021-12-05 17:54:36 +00:00
return ;
}
Mission * mission = missionComponent - > GetMission ( missionID ) ;
if ( mission ) {
mission - > SetReward ( reward ) ;
2022-07-28 13:39:57 +00:00
} else {
2023-10-21 23:31:55 +00:00
LOG ( " Unable to get mission %i for entity %llu to update reward in RespondToMission " , missionID , playerID ) ;
2021-12-05 17:54:36 +00:00
}
2023-07-15 20:56:33 +00:00
Entity * offerer = Game : : entityManager - > GetEntity ( receiverID ) ;
2021-12-05 17:54:36 +00:00
if ( offerer = = nullptr ) {
2023-10-21 23:31:55 +00:00
LOG ( " Unable to get receiver entity %llu for RespondToMission " , receiverID ) ;
2021-12-05 17:54:36 +00:00
return ;
}
2024-03-07 01:49:29 +00:00
offerer - > GetScript ( ) - > OnRespondToMission ( offerer , missionID , Game : : entityManager - > GetEntity ( playerID ) , reward ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleMissionDialogOK ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
bool bIsComplete { } ;
2023-01-22 23:38:47 +00:00
eMissionState iMissionState { } ;
2021-12-05 17:54:36 +00:00
int missionID { } ;
LWOOBJID responder { } ;
Entity * player = nullptr ;
2024-02-26 14:17:22 +00:00
inStream . Read ( bIsComplete ) ;
inStream . Read ( iMissionState ) ;
inStream . Read ( missionID ) ;
inStream . Read ( responder ) ;
2023-07-15 20:56:33 +00:00
player = Game : : entityManager - > GetEntity ( responder ) ;
2021-12-05 17:54:36 +00:00
2024-03-07 01:49:29 +00:00
if ( entity ) entity - > GetScript ( ) - > OnMissionDialogueOK ( entity , player , missionID , iMissionState ) ;
2021-12-05 17:54:36 +00:00
// Get the player's mission component
2023-03-04 07:16:37 +00:00
MissionComponent * missionComponent = static_cast < MissionComponent * > ( player - > GetComponent ( eReplicaComponentType : : MISSION ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! missionComponent ) {
2023-10-21 23:31:55 +00:00
LOG ( " Unable to get mission component for entity %llu to handle MissionDialogueOK " , player - > GetObjectID ( ) ) ;
2021-12-05 17:54:36 +00:00
return ;
}
2023-01-22 23:38:47 +00:00
if ( iMissionState = = eMissionState : : AVAILABLE | | iMissionState = = eMissionState : : COMPLETE_AVAILABLE ) {
2021-12-05 17:54:36 +00:00
missionComponent - > AcceptMission ( missionID ) ;
2023-01-22 23:38:47 +00:00
} else if ( iMissionState = = eMissionState : : READY_TO_COMPLETE | | iMissionState = = eMissionState : : COMPLETE_READY_TO_COMPLETE ) {
2021-12-05 17:54:36 +00:00
missionComponent - > CompleteMission ( missionID ) ;
}
2023-11-22 02:04:44 +00:00
if ( Game : : config - > GetValue ( " allow_players_to_skip_cinematics " ) ! = " 1 "
2024-12-11 03:10:54 +00:00
| | ! player - > GetCharacter ( )
| | ! player - > GetCharacter ( ) - > GetPlayerFlag ( ePlayerFlag : : DLU_SKIP_CINEMATICS ) ) return ;
2023-11-22 02:04:44 +00:00
player - > AddCallbackTimer ( 0.5f , [ player ] ( ) {
if ( ! player ) return ;
GameMessages : : SendEndCinematic ( player - > GetObjectID ( ) , u " " , player - > GetSystemAddress ( ) ) ;
2024-12-11 03:10:54 +00:00
} ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleRequestLinkedMission ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
LWOOBJID playerId { } ;
int missionId { } ;
bool bMissionOffered { } ;
2024-02-26 14:17:22 +00:00
inStream . Read ( playerId ) ;
inStream . Read ( missionId ) ;
inStream . Read ( bMissionOffered ) ;
2021-12-05 17:54:36 +00:00
2023-07-15 20:56:33 +00:00
auto * player = Game : : entityManager - > GetEntity ( playerId ) ;
2021-12-05 17:54:36 +00:00
2023-03-04 07:16:37 +00:00
auto * missionOfferComponent = static_cast < MissionOfferComponent * > ( entity - > GetComponent ( eReplicaComponentType : : MISSION_OFFER ) ) ;
2022-07-17 07:35:11 +00:00
2022-07-28 13:39:57 +00:00
if ( missionOfferComponent ! = nullptr ) {
2021-12-05 17:54:36 +00:00
missionOfferComponent - > OfferMissions ( player , 0 ) ;
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleHasBeenCollected ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
LWOOBJID playerID ;
2024-02-26 14:17:22 +00:00
inStream . Read ( playerID ) ;
2021-12-05 17:54:36 +00:00
2023-07-15 20:56:33 +00:00
Entity * player = Game : : entityManager - > GetEntity ( playerID ) ;
2021-12-05 17:54:36 +00:00
if ( ! player | | ! entity | | entity - > GetCollectibleID ( ) = = 0 ) return ;
2023-03-04 07:16:37 +00:00
MissionComponent * missionComponent = static_cast < MissionComponent * > ( player - > GetComponent ( eReplicaComponentType : : MISSION ) ) ;
2021-12-05 17:54:36 +00:00
if ( missionComponent ) {
2023-01-22 23:38:47 +00:00
missionComponent - > Progress ( eMissionTaskType : : COLLECTION , entity - > GetLOT ( ) , entity - > GetObjectID ( ) ) ;
2021-12-05 17:54:36 +00:00
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleNotifyServerLevelProcessingComplete ( RakNet : : BitStream & inStream , Entity * entity ) {
2022-07-24 18:04:02 +00:00
auto * levelComp = entity - > GetComponent < LevelProgressionComponent > ( ) ;
if ( ! levelComp ) return ;
auto * character = entity - > GetComponent < CharacterComponent > ( ) ;
2021-12-05 17:54:36 +00:00
if ( ! character ) return ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
//Update our character's level in memory:
2022-07-24 18:04:02 +00:00
levelComp - > SetLevel ( levelComp - > GetLevel ( ) + 1 ) ;
2021-12-05 17:54:36 +00:00
2022-07-24 18:04:02 +00:00
levelComp - > HandleLevelUp ( ) ;
2021-12-05 17:54:36 +00:00
auto * inventoryComponent = entity - > GetComponent < InventoryComponent > ( ) ;
if ( inventoryComponent ! = nullptr ) {
auto * inventory = inventoryComponent - > GetInventory ( ITEMS ) ;
if ( inventory ! = nullptr & & Game : : config - > GetValue ( " disable_extra_backpack " ) ! = " 1 " ) {
inventory - > SetSize ( inventory - > GetSize ( ) + 2 ) ;
}
}
//Play the level up effect:
GameMessages : : SendPlayFXEffect ( entity , 7074 , u " create " , " 7074 " , LWOOBJID_EMPTY , 1.0f , 1.0f , true ) ;
//Send a notification in chat:
std : : stringstream wss ;
wss < < " level=1: " ;
2022-07-24 18:04:02 +00:00
wss < < levelComp - > GetLevel ( ) ;
2021-12-05 17:54:36 +00:00
wss < < " \n " ;
wss < < " name=0: " ;
wss < < character - > GetName ( ) ;
2022-08-02 13:56:20 +00:00
// FIXME: only really need utf8 conversion for the name, so move that up?
std : : u16string attrs = GeneralUtils : : UTF8ToUTF16 ( wss . str ( ) ) ;
2021-12-05 17:54:36 +00:00
std : : u16string wsText = u " UI_LEVEL_PROGRESSION_LEVELUP_MESSAGE " ;
GameMessages : : SendBroadcastTextToChatbox ( entity , UNASSIGNED_SYSTEM_ADDRESS , attrs , wsText ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandlePickupCurrency ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
unsigned int currency ;
2024-02-26 14:17:22 +00:00
inStream . Read ( currency ) ;
2022-07-17 07:35:11 +00:00
2021-12-11 13:21:00 +00:00
if ( currency = = 0 ) return ;
2021-12-05 17:54:36 +00:00
auto * ch = entity - > GetCharacter ( ) ;
2021-12-11 13:57:15 +00:00
if ( entity - > CanPickupCoins ( currency ) ) {
2023-05-02 22:39:21 +00:00
ch - > SetCoins ( ch - > GetCoins ( ) + currency , eLootSourceType : : PICKUP ) ;
2021-12-11 13:21:00 +00:00
}
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleRequestDie ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
LWOOBJID killerID ;
LWOOBJID lootOwnerID ;
bool bDieAccepted = false ;
eKillType killType ;
std : : u16string deathType ;
float directionRelative_AngleY ;
float directionRelative_AngleXZ ;
float directionRelative_Force ;
bool bClientDeath = false ;
bool bSpawnLoot = true ;
float coinSpawnTime = - 1.0f ;
2024-02-26 14:17:22 +00:00
inStream . Read ( bClientDeath ) ;
inStream . Read ( bDieAccepted ) ;
inStream . Read ( bSpawnLoot ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
bool coinSpawnTimeIsDefault { } ;
2024-02-26 14:17:22 +00:00
inStream . Read ( coinSpawnTimeIsDefault ) ;
if ( coinSpawnTimeIsDefault ! = 0 ) inStream . Read ( coinSpawnTime ) ;
2021-12-05 17:54:36 +00:00
/*uint32_t deathTypeLength = deathType.size();
2024-02-26 14:17:22 +00:00
inStream . Read ( deathTypeLength ) ;
2021-12-05 17:54:36 +00:00
for ( uint32_t k = 0 ; k < deathTypeLength ; k + + ) {
2024-02-26 14:17:22 +00:00
inStream . Read < uint16_t > ( deathType [ k ] ) ;
2021-12-05 17:54:36 +00:00
} */
2024-02-26 14:17:22 +00:00
inStream . Read ( directionRelative_AngleXZ ) ;
inStream . Read ( directionRelative_AngleY ) ;
inStream . Read ( directionRelative_Force ) ;
2021-12-05 17:54:36 +00:00
bool killTypeIsDefault { } ;
2024-02-26 14:17:22 +00:00
inStream . Read ( killTypeIsDefault ) ;
if ( killTypeIsDefault ! = 0 ) inStream . Read ( killType ) ;
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
inStream . Read ( lootOwnerID ) ;
inStream . Read ( killerID ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleEquipItem ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
bool immediate ;
LWOOBJID objectID ;
2024-02-26 14:17:22 +00:00
inStream . Read ( immediate ) ;
inStream . Read ( immediate ) ; //twice?
inStream . Read ( objectID ) ;
2021-12-05 17:54:36 +00:00
2023-03-04 07:16:37 +00:00
InventoryComponent * inv = static_cast < InventoryComponent * > ( entity - > GetComponent ( eReplicaComponentType : : INVENTORY ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! inv ) return ;
Item * item = inv - > FindItemById ( objectID ) ;
if ( ! item ) return ;
2022-05-09 00:57:36 +00:00
2022-07-28 13:39:57 +00:00
item - > Equip ( ) ;
2022-07-17 07:35:11 +00:00
2023-07-15 20:56:33 +00:00
Game : : entityManager - > SerializeEntity ( entity ) ;
2022-07-28 13:39:57 +00:00
}
2021-12-05 17:54:36 +00:00
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleUnequipItem ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
bool immediate ;
LWOOBJID objectID ;
2024-02-26 14:17:22 +00:00
inStream . Read ( immediate ) ;
inStream . Read ( immediate ) ;
inStream . Read ( immediate ) ;
inStream . Read ( objectID ) ;
2021-12-05 17:54:36 +00:00
2023-03-04 07:16:37 +00:00
InventoryComponent * inv = static_cast < InventoryComponent * > ( entity - > GetComponent ( eReplicaComponentType : : INVENTORY ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! inv ) return ;
auto * item = inv - > FindItemById ( objectID ) ;
if ( ! item ) return ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
item - > UnEquip ( ) ;
2022-07-17 07:35:11 +00:00
2023-07-15 20:56:33 +00:00
Game : : entityManager - > SerializeEntity ( entity ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleRemoveItemFromInventory ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
// this is used for a lot more than just inventory trashing (trades, vendors, etc.) but for now since it's just used for that, that's all im going to implement
bool bConfirmed = false ;
bool bDeleteItem = true ;
bool bOutSuccess = false ;
bool eInvTypeIsDefault = false ;
int eInvType = INVENTORY_MAX ;
bool eLootTypeSourceIsDefault = false ;
int eLootTypeSource = LOOTTYPE_NONE ;
LWONameValue extraInfo ;
bool forceDeletion = true ;
bool iLootTypeSourceIsDefault = false ;
LWOOBJID iLootTypeSource = LWOOBJID_EMPTY ;
bool iObjIDIsDefault = false ;
2024-04-09 04:50:41 +00:00
LWOOBJID iObjID = LWOOBJID_EMPTY ;
2021-12-05 17:54:36 +00:00
bool iObjTemplateIsDefault = false ;
LOT iObjTemplate = LOT_NULL ;
bool iRequestingObjIDIsDefault = false ;
LWOOBJID iRequestingObjID = LWOOBJID_EMPTY ;
bool iStackCountIsDefault = false ;
uint32_t iStackCount = 1 ;
bool iStackRemainingIsDefault = false ;
uint32_t iStackRemaining = 0 ;
bool iSubkeyIsDefault = false ;
LWOOBJID iSubkey = LWOOBJID_EMPTY ;
bool iTradeIDIsDefault = false ;
LWOOBJID iTradeID = LWOOBJID_EMPTY ;
2024-02-26 14:17:22 +00:00
inStream . Read ( bConfirmed ) ;
inStream . Read ( bDeleteItem ) ;
inStream . Read ( bOutSuccess ) ;
inStream . Read ( eInvTypeIsDefault ) ;
if ( eInvTypeIsDefault ) inStream . Read ( eInvType ) ;
inStream . Read ( eLootTypeSourceIsDefault ) ;
if ( eLootTypeSourceIsDefault ) inStream . Read ( eLootTypeSource ) ;
inStream . Read ( extraInfo . length ) ;
2021-12-05 17:54:36 +00:00
if ( extraInfo . length > 0 ) {
for ( uint32_t i = 0 ; i < extraInfo . length ; + + i ) {
uint16_t character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2021-12-05 17:54:36 +00:00
extraInfo . name . push_back ( character ) ;
}
uint16_t nullTerm ;
2024-02-26 14:17:22 +00:00
inStream . Read ( nullTerm ) ;
}
inStream . Read ( forceDeletion ) ;
inStream . Read ( iLootTypeSourceIsDefault ) ;
if ( iLootTypeSourceIsDefault ) inStream . Read ( iLootTypeSource ) ;
inStream . Read ( iObjIDIsDefault ) ;
if ( iObjIDIsDefault ) inStream . Read ( iObjID ) ;
inStream . Read ( iObjTemplateIsDefault ) ;
if ( iObjTemplateIsDefault ) inStream . Read ( iObjTemplate ) ;
inStream . Read ( iRequestingObjIDIsDefault ) ;
if ( iRequestingObjIDIsDefault ) inStream . Read ( iRequestingObjID ) ;
inStream . Read ( iStackCountIsDefault ) ;
if ( iStackCountIsDefault ) inStream . Read ( iStackCount ) ;
inStream . Read ( iStackRemainingIsDefault ) ;
if ( iStackRemainingIsDefault ) inStream . Read ( iStackRemaining ) ;
inStream . Read ( iSubkeyIsDefault ) ;
if ( iSubkeyIsDefault ) inStream . Read ( iSubkey ) ;
inStream . Read ( iTradeIDIsDefault ) ;
if ( iTradeIDIsDefault ) inStream . Read ( iTradeID ) ;
2021-12-05 17:54:36 +00:00
2023-03-04 07:16:37 +00:00
InventoryComponent * inv = static_cast < InventoryComponent * > ( entity - > GetComponent ( eReplicaComponentType : : INVENTORY ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! inv ) return ;
auto * item = inv - > FindItemById ( iObjID ) ;
2022-07-28 13:39:57 +00:00
if ( item = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
2022-07-17 07:35:11 +00:00
2022-04-14 09:09:40 +00:00
iStackCount = std : : min < uint32_t > ( item - > GetCount ( ) , iStackCount ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
if ( bConfirmed ) {
2024-05-31 04:53:13 +00:00
const auto itemType = static_cast < eItemType > ( item - > GetInfo ( ) . itemType ) ;
if ( itemType = = eItemType : : MODEL | | itemType = = eItemType : : LOOT_MODEL ) {
2023-11-16 01:29:53 +00:00
item - > DisassembleModel ( iStackCount ) ;
2024-12-06 04:00:54 +00:00
} else if ( itemType = = eItemType : : VEHICLE ) {
Database : : Get ( ) - > DeleteUgcBuild ( item - > GetSubKey ( ) ) ;
2021-12-05 17:54:36 +00:00
}
2024-05-12 12:30:03 +00:00
auto lot = item - > GetLot ( ) ;
2021-12-05 17:54:36 +00:00
item - > SetCount ( item - > GetCount ( ) - iStackCount , true ) ;
2023-07-15 20:56:33 +00:00
Game : : entityManager - > SerializeEntity ( entity ) ;
2021-12-05 17:54:36 +00:00
auto * missionComponent = entity - > GetComponent < MissionComponent > ( ) ;
2022-07-17 07:35:11 +00:00
2022-07-28 13:39:57 +00:00
if ( missionComponent ! = nullptr ) {
2024-05-12 12:30:03 +00:00
missionComponent - > Progress ( eMissionTaskType : : GATHER , lot , LWOOBJID_EMPTY , " " , - iStackCount ) ;
2021-12-05 17:54:36 +00:00
}
}
}
2023-10-16 12:55:57 +00:00
void GameMessages : : SendSetGravityScale ( const LWOOBJID & target , const float effectScale , const SystemAddress & sysAddr ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( target ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_GRAVITY_SCALE ) ;
2023-10-16 12:55:57 +00:00
bitStream . Write ( effectScale ) ;
SEND_PACKET ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleMoveItemInInventory ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
bool destInvTypeIsDefault = false ;
int32_t destInvType = eInventoryType : : INVALID ;
LWOOBJID iObjID ;
int inventoryType ;
int responseCode ;
int slot ;
2024-02-26 14:17:22 +00:00
inStream . Read ( destInvTypeIsDefault ) ;
if ( destInvTypeIsDefault ) { inStream . Read ( destInvType ) ; }
inStream . Read ( iObjID ) ;
inStream . Read ( inventoryType ) ;
inStream . Read ( responseCode ) ;
inStream . Read ( slot ) ;
2021-12-05 17:54:36 +00:00
2023-03-04 07:16:37 +00:00
InventoryComponent * inv = static_cast < InventoryComponent * > ( entity - > GetComponent ( eReplicaComponentType : : INVENTORY ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! inv ) return ;
auto * item = inv - > FindItemById ( iObjID ) ;
2022-07-28 13:39:57 +00:00
if ( ! item ) {
2021-12-05 17:54:36 +00:00
return ;
}
inv - > MoveStack ( item , static_cast < eInventoryType > ( destInvType ) , slot ) ;
2023-07-15 20:56:33 +00:00
Game : : entityManager - > SerializeEntity ( entity ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleMoveItemBetweenInventoryTypes ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2022-04-24 03:32:31 +00:00
eInventoryType inventoryTypeA ;
eInventoryType inventoryTypeB ;
2021-12-05 17:54:36 +00:00
LWOOBJID objectID ;
bool showFlyingLoot = true ;
bool stackCountIsDefault = false ;
uint32_t stackCount = 1 ;
bool templateIDIsDefault = false ;
LOT templateID = LOT_NULL ;
2024-02-26 14:17:22 +00:00
inStream . Read ( inventoryTypeA ) ;
inStream . Read ( inventoryTypeB ) ;
inStream . Read ( objectID ) ;
inStream . Read ( showFlyingLoot ) ;
inStream . Read ( stackCountIsDefault ) ;
if ( stackCountIsDefault ) inStream . Read ( stackCount ) ;
inStream . Read ( templateIDIsDefault ) ;
if ( templateIDIsDefault ) inStream . Read ( templateID ) ;
2021-12-05 17:54:36 +00:00
2022-04-24 03:32:31 +00:00
auto inv = entity - > GetComponent < InventoryComponent > ( ) ;
2021-12-05 17:54:36 +00:00
if ( ! inv ) return ;
auto * item = inv - > FindItemById ( objectID ) ;
2022-07-06 06:18:04 +00:00
if ( ! item ) {
// Attempt to find the item by lot in inventory A since A is the source inventory.
item = inv - > FindItemByLot ( templateID , static_cast < eInventoryType > ( inventoryTypeA ) ) ;
if ( ! item ) {
// As a final resort, try to find the item in its default inventory based on type.
item = inv - > FindItemByLot ( templateID ) ;
if ( ! item ) {
return ;
}
2021-12-05 17:54:36 +00:00
}
}
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
if ( entity - > GetCharacter ( ) ) {
if ( entity - > GetCharacter ( ) - > GetBuildMode ( ) ) {
showFlyingLoot = false ;
}
}
2022-04-24 03:32:31 +00:00
inv - > MoveItemToInventory ( item , inventoryTypeB , stackCount , showFlyingLoot ) ;
2023-07-15 20:56:33 +00:00
Game : : entityManager - > SerializeEntity ( entity ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleBuildModeSet ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
bool bStart = false ;
2024-02-26 14:17:22 +00:00
inStream . Read ( bStart ) ;
2021-12-05 17:54:36 +00:00
// there's more here but we don't need it (for now?)
2023-10-21 23:31:55 +00:00
LOG ( " Set build mode to (%d) for (%llu) " , bStart , entity - > GetObjectID ( ) ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
if ( entity - > GetCharacter ( ) ) {
entity - > GetCharacter ( ) - > SetBuildMode ( bStart ) ;
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleModularBuildFinish ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
User * user = UserManager : : Instance ( ) - > GetUser ( sysAddr ) ;
if ( ! user ) return ;
2023-07-15 20:56:33 +00:00
Entity * character = Game : : entityManager - > GetEntity ( user - > GetLoggedInChar ( ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! character ) return ;
2023-03-04 07:16:37 +00:00
InventoryComponent * inv = static_cast < InventoryComponent * > ( character - > GetComponent ( eReplicaComponentType : : INVENTORY ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! inv ) return ;
uint8_t count ; // 3 for rockets, 7 for cars
2024-02-26 14:17:22 +00:00
inStream . Read ( count ) ;
2021-12-05 17:54:36 +00:00
auto * temp = inv - > GetInventory ( TEMP_MODELS ) ;
std : : vector < LOT > modList ;
2022-12-31 19:44:09 +00:00
auto & oldPartList = character - > GetVar < std : : string > ( u " currentModifiedBuild " ) ;
bool everyPieceSwapped = ! oldPartList . empty ( ) ; // If the player didn't put a build in initially, then they should not get this achievement.
2021-12-05 17:54:36 +00:00
if ( count > = 3 ) {
std : : u16string modules ;
for ( uint32_t k = 0 ; k < count ; k + + ) {
uint32_t mod ;
2024-02-26 14:17:22 +00:00
inStream . Read ( mod ) ;
2021-12-05 17:54:36 +00:00
modList . push_back ( mod ) ;
2022-12-31 19:44:09 +00:00
auto modToStr = GeneralUtils : : to_u16string ( mod ) ;
modules + = u " 1: " + ( modToStr ) ;
2021-12-05 17:54:36 +00:00
if ( k + 1 ! = count ) modules + = u " + " ;
2022-07-28 13:39:57 +00:00
if ( temp - > GetLotCount ( mod ) > 0 ) {
2021-12-05 17:54:36 +00:00
inv - > RemoveItem ( mod , 1 , TEMP_MODELS ) ;
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
inv - > RemoveItem ( mod , 1 ) ;
}
2022-12-31 19:44:09 +00:00
// Doing this check for 1 singular mission that needs to know when you've swapped every part out during a car modular build.
// since all 8129's are the same, skip checking that
if ( mod ! = 8129 ) {
if ( oldPartList . find ( GeneralUtils : : UTF16ToWTF8 ( modToStr ) ) ! = std : : string : : npos ) everyPieceSwapped = false ;
}
2021-12-05 17:54:36 +00:00
}
2024-01-05 12:31:22 +00:00
ObjectIDManager : : RequestPersistentID ( [ = ] ( uint32_t newId ) {
2023-11-16 01:32:30 +00:00
LOG ( " Build finished " ) ;
GameMessages : : SendFinishArrangingWithItem ( character , entity - > GetObjectID ( ) ) ; // kick them from modular build
GameMessages : : SendModularBuildEnd ( character ) ; // i dont know if this does anything but DLUv2 did it
//inv->UnequipItem(inv->GetItemStackByLOT(6086, eInventoryType::ITEMS)); // take off the thinking cap
//Game::entityManager->SerializeEntity(entity);
const auto moduleAssembly = new LDFData < std : : u16string > ( u " assemblyPartLOTs " , modules ) ;
2021-12-05 17:54:36 +00:00
2023-11-16 01:32:30 +00:00
std : : vector < LDFBaseData * > config ;
config . push_back ( moduleAssembly ) ;
2021-12-05 17:54:36 +00:00
2023-11-16 01:32:30 +00:00
LWOOBJID newIdBig = newId ;
2023-11-08 18:18:02 +00:00
GeneralUtils : : SetBit ( newIdBig , eObjectBits : : CHARACTER ) ;
2023-11-16 01:32:30 +00:00
if ( count = = 3 ) {
inv - > AddItem ( 6416 , 1 , eLootSourceType : : QUICKBUILD , eInventoryType : : MODELS , config , LWOOBJID_EMPTY , true , false , newIdBig ) ;
} else if ( count = = 7 ) {
inv - > AddItem ( 8092 , 1 , eLootSourceType : : QUICKBUILD , eInventoryType : : MODELS , config , LWOOBJID_EMPTY , true , false , newIdBig ) ;
}
2021-12-05 17:54:36 +00:00
2023-11-16 01:32:30 +00:00
auto * pCharacter = character - > GetCharacter ( ) ;
2024-12-06 04:00:54 +00:00
Database : : Get ( ) - > InsertUgcBuild ( GeneralUtils : : UTF16ToWTF8 ( modules ) , newIdBig , pCharacter ? std : : optional ( character - > GetCharacter ( ) - > GetID ( ) ) : std : : nullopt ) ;
2022-07-17 07:35:11 +00:00
2023-11-16 01:32:30 +00:00
auto * missionComponent = character - > GetComponent < MissionComponent > ( ) ;
if ( entity - > GetLOT ( ) ! = 9980 | | Game : : server - > GetZoneID ( ) ! = 1200 ) {
if ( missionComponent ! = nullptr ) {
missionComponent - > Progress ( eMissionTaskType : : SCRIPT , entity - > GetLOT ( ) , entity - > GetObjectID ( ) ) ;
2023-12-24 00:11:00 +00:00
if ( count > = 7 & & everyPieceSwapped ) missionComponent - > Progress ( eMissionTaskType : : RACING , LWOOBJID_EMPTY , static_cast < LWOOBJID > ( eRacingTaskParam : : MODULAR_BUILDING ) ) ;
2023-11-16 01:32:30 +00:00
}
2021-12-05 17:54:36 +00:00
}
2023-11-16 01:32:30 +00:00
ScriptComponent * script = static_cast < ScriptComponent * > ( entity - > GetComponent ( eReplicaComponentType : : SCRIPT ) ) ;
2021-12-05 17:54:36 +00:00
2024-03-07 01:49:29 +00:00
entity - > GetScript ( ) - > OnModularBuildExit ( entity , character , count > = 3 , modList ) ;
2021-12-05 17:54:36 +00:00
2023-11-16 01:32:30 +00:00
// Move remaining temp models back to models
std : : vector < Item * > items ;
2021-12-05 17:54:36 +00:00
2023-11-16 01:32:30 +00:00
for ( const auto & pair : temp - > GetItems ( ) ) {
items . push_back ( pair . second ) ;
}
2021-12-05 17:54:36 +00:00
2023-11-16 01:32:30 +00:00
for ( auto * item : items ) {
inv - > MoveItemToInventory ( item , eInventoryType : : MODELS , item - > GetCount ( ) , false ) ;
}
} ) ;
2021-12-05 17:54:36 +00:00
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleDoneArrangingWithItem ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
User * user = UserManager : : Instance ( ) - > GetUser ( sysAddr ) ;
if ( ! user ) return ;
2023-07-15 20:56:33 +00:00
Entity * character = Game : : entityManager - > GetEntity ( user - > GetLoggedInChar ( ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! character ) return ;
2023-03-04 07:16:37 +00:00
InventoryComponent * inv = static_cast < InventoryComponent * > ( character - > GetComponent ( eReplicaComponentType : : INVENTORY ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! inv ) return ;
/**
[ int ] - newSourceBAG
[ LWOOBJID ] - newSourceID
[ LOT ] - newSourceLOT
[ int ] - newSourceTYPE
[ LWOOBJID ] - newTargetID
[ LOT ] - newTargetLOT
[ int ] - newTargetTYPE
[ NiPoint3 ] - newTtargetPOS
[ int ] - oldItemBAG
[ LWOOBJID ] - oldItemID
[ LOT ] - oldItemLOT
[ int ] - oldItemTYPE
*/
int newSourceBAG = 0 ;
LWOOBJID newSourceID = 0 ;
LOT newSourceLOT = 0 ;
int newSourceTYPE = 0 ;
LWOOBJID newTargetID = 0 ;
LOT newTargetLOT = 0 ;
int newTargetTYPE = 0 ;
NiPoint3 newTargetPOS ;
int oldItemBAG = 0 ;
LWOOBJID oldItemID = 0 ;
LOT oldItemLOT = 0 ;
int oldItemTYPE = 0 ;
2024-02-26 14:17:22 +00:00
inStream . Read ( newSourceBAG ) ;
inStream . Read ( newSourceID ) ;
inStream . Read ( newSourceLOT ) ;
inStream . Read ( newSourceTYPE ) ;
inStream . Read ( newTargetID ) ;
inStream . Read ( newTargetLOT ) ;
inStream . Read ( newTargetTYPE ) ;
inStream . Read ( newTargetPOS ) ;
inStream . Read ( oldItemBAG ) ;
inStream . Read ( oldItemID ) ;
inStream . Read ( oldItemLOT ) ;
inStream . Read ( oldItemTYPE ) ;
2021-12-05 17:54:36 +00:00
/*
2023-10-21 23:31:55 +00:00
LOG ( " GameMessages " ,
2022-07-25 02:26:51 +00:00
" \n newSourceBAG: %d \n newSourceID: %llu \n newSourceLOT: %d \n newSourceTYPE: %d \n newTargetID: %llu \n newTargetLOT: %d \n newTargetTYPE: %d \n newTargetPOS: %f, %f, %f \n oldItemBAG: %d \n oldItemID: %llu \n oldItemLOT: %d \n oldItemTYPE: %d " ,
2021-12-05 17:54:36 +00:00
newSourceBAG , newSourceID , newSourceLOT , newSourceTYPE , newTargetID , newTargetLOT , newTargetTYPE , newTargetPOS . x , newTargetPOS . y , newTargetPOS . z , oldItemBAG , oldItemID , oldItemLOT , oldItemTYPE
) ;
*/
if ( PropertyManagementComponent : : Instance ( ) ! = nullptr ) {
2023-07-15 20:56:33 +00:00
const auto & buildAreas = Game : : entityManager - > GetEntitiesByComponent ( eReplicaComponentType : : BUILD_BORDER ) ;
2022-07-17 07:35:11 +00:00
2023-07-15 20:56:33 +00:00
const auto & entities = Game : : entityManager - > GetEntitiesInGroup ( " PropertyPlaque " ) ;
2021-12-05 17:54:36 +00:00
Entity * buildArea ;
if ( ! buildAreas . empty ( ) ) {
buildArea = buildAreas [ 0 ] ;
2022-07-28 13:39:57 +00:00
} else if ( ! entities . empty ( ) ) {
2021-12-05 17:54:36 +00:00
buildArea = entities [ 0 ] ;
2022-07-17 07:35:11 +00:00
2023-10-21 23:31:55 +00:00
LOG ( " Using PropertyPlaque " ) ;
2022-07-28 13:39:57 +00:00
} else {
2023-10-21 23:31:55 +00:00
LOG ( " No build area found " ) ;
2021-12-05 17:54:36 +00:00
return ;
}
2023-10-21 23:31:55 +00:00
LOG ( " Build area found: %llu " , buildArea - > GetObjectID ( ) ) ;
2021-12-05 17:54:36 +00:00
GameMessages : : SendStartArrangingWithItem (
character ,
character - > GetSystemAddress ( ) ,
false ,
buildArea - > GetObjectID ( ) ,
character - > GetPosition ( ) ,
newSourceBAG ,
newSourceID ,
newSourceLOT ,
newSourceTYPE ,
newTargetID ,
newTargetLOT ,
newTargetPOS ,
newTargetTYPE
) ;
}
2023-10-21 23:31:55 +00:00
LOG ( " Done Arranging " ) ;
2021-12-05 17:54:36 +00:00
//GenericInventory* models = inv->GetGenericInventory(MODELS);
//GenericInventory* tempModels = inv->GetGenericInventory(TEMP_MODELS);
auto * inventory = inv - > GetInventory ( TEMP_MODELS ) ;
std : : vector < Item * > items ;
2022-07-28 13:39:57 +00:00
for ( const auto & pair : inventory - > GetItems ( ) ) {
2021-12-05 17:54:36 +00:00
items . push_back ( pair . second ) ;
}
2022-07-28 13:39:57 +00:00
for ( auto * item : items ) {
2022-04-24 03:32:31 +00:00
inv - > MoveItemToInventory ( item , eInventoryType : : MODELS , item - > GetCount ( ) , false , false ) ;
2021-12-05 17:54:36 +00:00
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleModularBuildMoveAndEquip ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
User * user = UserManager : : Instance ( ) - > GetUser ( sysAddr ) ;
if ( ! user ) return ;
2023-07-15 20:56:33 +00:00
Entity * character = Game : : entityManager - > GetEntity ( user - > GetLoggedInChar ( ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! character ) return ;
2023-10-21 23:31:55 +00:00
LOG ( " Build and move " ) ;
2021-12-05 17:54:36 +00:00
LOT templateID ;
2024-02-26 14:17:22 +00:00
inStream . Read ( templateID ) ;
2021-12-05 17:54:36 +00:00
2023-03-04 07:16:37 +00:00
InventoryComponent * inv = static_cast < InventoryComponent * > ( character - > GetComponent ( eReplicaComponentType : : INVENTORY ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! inv ) return ;
auto * item = inv - > FindItemByLot ( templateID , TEMP_MODELS ) ;
2022-07-28 13:39:57 +00:00
if ( item = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
2022-04-24 03:32:31 +00:00
inv - > MoveItemToInventory ( item , eInventoryType : : MODELS , 1 , false , true ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandlePickupItem ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
LWOOBJID lootObjectID ;
LWOOBJID playerID ;
2024-02-26 14:17:22 +00:00
inStream . Read ( lootObjectID ) ;
inStream . Read ( playerID ) ;
2021-12-05 17:54:36 +00:00
entity - > PickupItem ( lootObjectID ) ;
auto * team = TeamManager : : Instance ( ) - > GetTeam ( entity - > GetObjectID ( ) ) ;
2022-07-28 13:39:57 +00:00
if ( team ! = nullptr ) {
for ( const auto memberId : team - > members ) {
2023-07-15 20:56:33 +00:00
auto * member = Game : : entityManager - > GetEntity ( memberId ) ;
2021-12-05 17:54:36 +00:00
if ( member = = nullptr | | memberId = = playerID ) continue ;
SendTeamPickupItem ( lootObjectID , lootObjectID , playerID , member - > GetSystemAddress ( ) ) ;
}
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleResurrect ( RakNet : : BitStream & inStream , Entity * entity ) {
bool immediate = inStream . ReadBit ( ) ;
2021-12-05 17:54:36 +00:00
2023-07-15 20:56:33 +00:00
Entity * zoneControl = Game : : entityManager - > GetZoneControlEntity ( ) ;
2024-03-07 01:49:29 +00:00
if ( zoneControl ) {
zoneControl - > GetScript ( ) - > OnPlayerResurrected ( zoneControl , entity ) ;
2022-07-23 02:58:20 +00:00
}
2021-12-05 17:54:36 +00:00
2023-07-15 20:56:33 +00:00
std : : vector < Entity * > scriptedActs = Game : : entityManager - > GetEntitiesByComponent ( eReplicaComponentType : : SCRIPTED_ACTIVITY ) ;
2022-07-23 02:58:20 +00:00
for ( Entity * scriptEntity : scriptedActs ) {
if ( scriptEntity - > GetObjectID ( ) ! = zoneControl - > GetObjectID ( ) ) { // Don't want to trigger twice on instance worlds
2024-03-07 01:49:29 +00:00
scriptEntity - > GetScript ( ) - > OnPlayerResurrected ( scriptEntity , entity ) ;
2022-07-23 02:58:20 +00:00
}
}
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandlePushEquippedItemsState ( RakNet : : BitStream & inStream , Entity * entity ) {
2023-03-04 07:16:37 +00:00
InventoryComponent * inv = static_cast < InventoryComponent * > ( entity - > GetComponent ( eReplicaComponentType : : INVENTORY ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! inv ) return ;
inv - > PushEquippedItems ( ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandlePopEquippedItemsState ( RakNet : : BitStream & inStream , Entity * entity ) {
2023-03-04 07:16:37 +00:00
InventoryComponent * inv = static_cast < InventoryComponent * > ( entity - > GetComponent ( eReplicaComponentType : : INVENTORY ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! inv ) return ;
inv - > PopEquippedItems ( ) ;
2023-07-15 20:56:33 +00:00
Game : : entityManager - > SerializeEntity ( entity ) ; // so it updates on client side
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleClientItemConsumed ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
LWOOBJID itemConsumed ;
2024-02-26 14:17:22 +00:00
inStream . Read ( itemConsumed ) ;
2021-12-05 17:54:36 +00:00
2023-03-04 07:16:37 +00:00
auto * inventory = static_cast < InventoryComponent * > ( entity - > GetComponent ( eReplicaComponentType : : INVENTORY ) ) ;
2022-07-17 07:35:11 +00:00
2022-07-28 13:39:57 +00:00
if ( inventory = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
auto * item = inventory - > FindItemById ( itemConsumed ) ;
2022-07-28 13:39:57 +00:00
if ( item = = nullptr ) {
2021-12-05 17:54:36 +00:00
return ;
}
2022-12-19 08:07:43 +00:00
LOT itemLot = item - > GetLot ( ) ;
2021-12-05 17:54:36 +00:00
item - > Consume ( ) ;
2023-03-04 07:16:37 +00:00
auto * missions = static_cast < MissionComponent * > ( entity - > GetComponent ( eReplicaComponentType : : MISSION ) ) ;
2022-07-28 13:39:57 +00:00
if ( missions ! = nullptr ) {
2023-01-22 23:38:47 +00:00
missions - > Progress ( eMissionTaskType : : USE_ITEM , itemLot ) ;
2021-12-05 17:54:36 +00:00
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleUseNonEquipmentItem ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
LWOOBJID itemConsumed ;
2024-02-26 14:17:22 +00:00
inStream . Read ( itemConsumed ) ;
2022-07-17 07:35:11 +00:00
2023-03-04 07:16:37 +00:00
auto * inv = static_cast < InventoryComponent * > ( entity - > GetComponent ( eReplicaComponentType : : INVENTORY ) ) ;
2022-07-17 07:35:11 +00:00
2021-12-05 17:54:36 +00:00
if ( ! inv ) return ;
auto * item = inv - > FindItemById ( itemConsumed ) ;
2022-07-17 07:35:11 +00:00
2022-12-24 22:41:13 +00:00
if ( item ) item - > UseNonEquip ( item ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleMatchRequest ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
LWOOBJID activator ;
//std::map<LWOOBJID, LWONameValue> additionalPlayers;
uint32_t playerChoicesLen ;
std : : string playerChoices ;
int type ;
int value ;
2024-02-26 14:17:22 +00:00
inStream . Read ( activator ) ;
inStream . Read ( playerChoicesLen ) ;
2021-12-05 17:54:36 +00:00
for ( uint32_t i = 0 ; i < playerChoicesLen ; + + i ) {
uint16_t character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2021-12-05 17:54:36 +00:00
playerChoices . push_back ( character ) ;
}
if ( playerChoicesLen > 0 ) {
uint16_t nullTerm ;
2024-02-26 14:17:22 +00:00
inStream . Read ( nullTerm ) ;
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
inStream . Read ( type ) ;
inStream . Read ( value ) ;
2021-12-05 17:54:36 +00:00
2023-07-15 20:56:33 +00:00
std : : vector < Entity * > scriptedActs = Game : : entityManager - > GetEntitiesByComponent ( eReplicaComponentType : : SCRIPTED_ACTIVITY ) ;
2021-12-05 17:54:36 +00:00
if ( type = = 0 ) { // join
if ( value ! = 0 ) {
for ( Entity * scriptedAct : scriptedActs ) {
2023-03-04 07:16:37 +00:00
ScriptedActivityComponent * comp = static_cast < ScriptedActivityComponent * > ( scriptedAct - > GetComponent ( eReplicaComponentType : : SCRIPTED_ACTIVITY ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! comp ) continue ;
if ( comp - > GetActivityID ( ) = = value ) {
comp - > PlayerJoin ( entity ) ;
}
}
2022-07-28 13:39:57 +00:00
} else {
2021-12-05 17:54:36 +00:00
}
2022-07-28 13:39:57 +00:00
} else if ( type = = 1 ) { // ready/unready
2021-12-05 17:54:36 +00:00
for ( Entity * scriptedAct : scriptedActs ) {
2023-03-04 07:16:37 +00:00
ScriptedActivityComponent * comp = static_cast < ScriptedActivityComponent * > ( scriptedAct - > GetComponent ( eReplicaComponentType : : SCRIPTED_ACTIVITY ) ) ;
2021-12-05 17:54:36 +00:00
if ( ! comp ) continue ;
if ( comp - > PlayerIsInQueue ( entity ) ) {
comp - > PlayerReady ( entity , value ) ;
}
}
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleGetHotPropertyData ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2022-07-23 02:58:20 +00:00
SendGetHotPropertyData ( inStream , entity , sysAddr ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : SendGetHotPropertyData ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2022-08-05 13:40:12 +00:00
CBITSTREAM ;
CMSGHEADER ;
/**
* [ u32 ] - Number of properties
* [ objid ] - property id
* [ objid ] - property owner id
* [ wstring ] - property owner name
* [ u64 ] - total reputation
* [ i32 ] - property template id
* [ wstring ] - property name
* [ wstring ] - property description
* [ float ] - performance cost
* [ timestamp ] - time last published
* [ cloneid ] - clone id
*
*/
// TODO This needs to be implemented when reputation is implemented for getting hot properties.
/**
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SEND_HOT_PROPERTY_DATA ) ;
2022-08-05 13:40:12 +00:00
std : : vector < int32_t > t = { 25166 , 25188 , 25191 , 25194 } ;
bitStream . Write < uint32_t > ( 4 ) ;
for ( uint8_t i = 0 ; i < 4 ; i + + ) {
bitStream . Write < LWOOBJID > ( entity - > GetObjectID ( ) ) ;
bitStream . Write < LWOOBJID > ( entity - > GetObjectID ( ) ) ;
bitStream . Write < uint32_t > ( 1 ) ;
bitStream . Write < uint16_t > ( ' c ' ) ;
bitStream . Write < uint64_t > ( 42069 ) ;
bitStream . Write < int32_t > ( t [ i ] ) ;
bitStream . Write < uint32_t > ( 1 ) ;
bitStream . Write < uint16_t > ( ' c ' ) ;
bitStream . Write < uint32_t > ( 1 ) ;
bitStream . Write < uint16_t > ( ' c ' ) ;
bitStream . Write < float > ( 420.69f ) ;
bitStream . Write < uint64_t > ( 1658376385 ) ;
bitStream . Write < int32_t > ( 25166 ) ;
}
SEND_PACKET */
2022-07-23 02:58:20 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleReportBug ( RakNet : : BitStream & inStream , Entity * entity ) {
2021-12-05 17:54:36 +00:00
//Definitely not stolen from autogenerated code, no sir:
2023-11-18 00:47:18 +00:00
IBugReports : : Info reportInfo ;
2021-12-05 17:54:36 +00:00
//Reading:
2023-11-18 00:47:18 +00:00
uint32_t messageLength ;
2024-02-26 14:17:22 +00:00
inStream . Read ( messageLength ) ;
2021-12-05 17:54:36 +00:00
for ( uint32_t i = 0 ; i < ( messageLength ) ; + + i ) {
uint16_t character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2023-11-18 00:47:18 +00:00
reportInfo . body . push_back ( static_cast < char > ( character ) ) ;
2021-12-05 17:54:36 +00:00
}
2022-03-21 03:28:26 +00:00
auto character = entity - > GetCharacter ( ) ;
2023-11-18 00:47:18 +00:00
if ( character ) reportInfo . characterId = character - > GetID ( ) ;
2022-03-21 03:28:26 +00:00
2021-12-05 17:54:36 +00:00
uint32_t clientVersionLength ;
2024-02-26 14:17:22 +00:00
inStream . Read ( clientVersionLength ) ;
2021-12-05 17:54:36 +00:00
for ( unsigned int k = 0 ; k < clientVersionLength ; k + + ) {
unsigned char character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2023-11-18 00:47:18 +00:00
reportInfo . clientVersion . push_back ( character ) ;
2021-12-05 17:54:36 +00:00
}
uint32_t nOtherPlayerIDLength ;
2024-02-26 14:17:22 +00:00
inStream . Read ( nOtherPlayerIDLength ) ;
2021-12-05 17:54:36 +00:00
for ( unsigned int k = 0 ; k < nOtherPlayerIDLength ; k + + ) {
unsigned char character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2023-11-18 00:47:18 +00:00
reportInfo . otherPlayer . push_back ( character ) ;
2021-12-05 17:54:36 +00:00
}
uint32_t selectionLength ;
2024-02-26 14:17:22 +00:00
inStream . Read ( selectionLength ) ;
2021-12-05 17:54:36 +00:00
for ( unsigned int k = 0 ; k < selectionLength ; k + + ) {
unsigned char character ;
2024-02-26 14:17:22 +00:00
inStream . Read ( character ) ;
2023-11-18 00:47:18 +00:00
reportInfo . selection . push_back ( character ) ;
2021-12-05 17:54:36 +00:00
}
2023-11-18 00:47:18 +00:00
Database : : Get ( ) - > InsertNewBugReport ( reportInfo ) ;
2021-12-05 17:54:36 +00:00
}
void
2024-02-26 14:17:22 +00:00
GameMessages : : HandleClientRailMovementReady ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2023-07-15 20:56:33 +00:00
const auto possibleRails = Game : : entityManager - > GetEntitiesByComponent ( eReplicaComponentType : : RAIL_ACTIVATOR ) ;
2022-07-23 02:58:20 +00:00
for ( const auto * possibleRail : possibleRails ) {
const auto * rail = possibleRail - > GetComponent < RailActivatorComponent > ( ) ;
if ( rail ! = nullptr ) {
rail - > OnRailMovementReady ( entity ) ;
}
}
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleCancelRailMovement ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
const auto immediate = inStream . ReadBit ( ) ;
2021-12-05 17:54:36 +00:00
2023-07-15 20:56:33 +00:00
const auto possibleRails = Game : : entityManager - > GetEntitiesByComponent ( eReplicaComponentType : : RAIL_ACTIVATOR ) ;
2022-07-23 02:58:20 +00:00
for ( const auto * possibleRail : possibleRails ) {
auto * rail = possibleRail - > GetComponent < RailActivatorComponent > ( ) ;
if ( rail ! = nullptr ) {
rail - > OnCancelRailMovement ( entity ) ;
}
}
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandlePlayerRailArrivedNotification ( RakNet : : BitStream & inStream , Entity * entity ,
2022-07-28 13:39:57 +00:00
const SystemAddress & sysAddr ) {
2021-12-05 17:54:36 +00:00
uint32_t pathNameLength ;
2024-02-26 14:17:22 +00:00
inStream . Read ( pathNameLength ) ;
2021-12-05 17:54:36 +00:00
std : : u16string pathName ;
for ( auto k = 0 ; k < pathNameLength ; k + + ) {
uint16_t c ;
2024-02-26 14:17:22 +00:00
inStream . Read ( c ) ;
2021-12-05 17:54:36 +00:00
pathName . push_back ( c ) ;
}
int32_t waypointNumber ;
2024-02-26 14:17:22 +00:00
inStream . Read ( waypointNumber ) ;
2021-12-05 17:54:36 +00:00
2023-07-15 20:56:33 +00:00
const auto possibleRails = Game : : entityManager - > GetEntitiesByComponent ( eReplicaComponentType : : RAIL_ACTIVATOR ) ;
2021-12-05 17:54:36 +00:00
for ( auto * possibleRail : possibleRails ) {
2024-03-07 01:49:29 +00:00
if ( possibleRail ) possibleRail - > GetScript ( ) - > OnPlayerRailArrived ( possibleRail , entity , pathName , waypointNumber ) ;
2021-12-05 17:54:36 +00:00
}
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleModifyPlayerZoneStatistic ( RakNet : : BitStream & inStream , Entity * entity ) {
const auto set = inStream . ReadBit ( ) ;
2022-07-23 02:58:20 +00:00
const auto statisticsName = GeneralUtils : : ReadWString ( inStream ) ;
int32_t value ;
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) {
inStream . Read < int32_t > ( value ) ;
2022-07-23 02:58:20 +00:00
} else {
value = 0 ;
}
LWOMAPID zone ;
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) {
inStream . Read < LWOMAPID > ( zone ) ;
2022-07-23 02:58:20 +00:00
} else {
zone = LWOMAPID_INVALID ;
}
// Notify the character component that something's changed
auto * characterComponent = entity - > GetComponent < CharacterComponent > ( ) ;
if ( characterComponent ! = nullptr ) {
characterComponent - > HandleZoneStatisticsUpdate ( zone , statisticsName , value ) ;
}
2021-12-05 17:54:36 +00:00
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleUpdatePlayerStatistic ( RakNet : : BitStream & inStream , Entity * entity ) {
2022-07-23 02:58:20 +00:00
int32_t updateID ;
2024-02-26 14:17:22 +00:00
inStream . Read < int32_t > ( updateID ) ;
2022-07-23 02:58:20 +00:00
int64_t updateValue ;
2024-02-26 14:17:22 +00:00
if ( inStream . ReadBit ( ) ) {
inStream . Read < int64_t > ( updateValue ) ;
2022-07-23 02:58:20 +00:00
} else {
updateValue = 1 ;
}
auto * characterComponent = entity - > GetComponent < CharacterComponent > ( ) ;
if ( characterComponent ! = nullptr ) {
2023-12-28 04:18:20 +00:00
characterComponent - > UpdatePlayerStatistic ( static_cast < StatisticID > ( updateID ) , static_cast < uint64_t > ( std : : max ( updateValue , static_cast < int64_t > ( 0 ) ) ) ) ;
2022-07-23 02:58:20 +00:00
}
2021-12-05 17:54:36 +00:00
}
2023-01-07 06:14:51 +00:00
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleDeactivateBubbleBuff ( RakNet : : BitStream & inStream , Entity * entity ) {
2023-01-07 06:14:51 +00:00
auto controllablePhysicsComponent = entity - > GetComponent < ControllablePhysicsComponent > ( ) ;
if ( controllablePhysicsComponent ) controllablePhysicsComponent - > DeactivateBubbleBuff ( ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleActivateBubbleBuff ( RakNet : : BitStream & inStream , Entity * entity ) {
2023-01-07 06:14:51 +00:00
bool specialAnimations ;
2024-02-26 14:17:22 +00:00
if ( ! inStream . Read ( specialAnimations ) ) return ;
2023-01-07 06:14:51 +00:00
std : : u16string type = GeneralUtils : : ReadWString ( inStream ) ;
auto bubbleType = eBubbleType : : DEFAULT ;
if ( type = = u " skunk " ) bubbleType = eBubbleType : : SKUNK ;
else if ( type = = u " energy " ) bubbleType = eBubbleType : : ENERGY ;
auto controllablePhysicsComponent = entity - > GetComponent < ControllablePhysicsComponent > ( ) ;
if ( controllablePhysicsComponent ) controllablePhysicsComponent - > ActivateBubbleBuff ( bubbleType , specialAnimations ) ;
}
void GameMessages : : SendActivateBubbleBuffFromServer ( LWOOBJID objectId , const SystemAddress & sysAddr ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : ACTIVATE_BUBBLE_BUFF_FROM_SERVER ) ;
2023-01-07 06:14:51 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
void GameMessages : : SendDeactivateBubbleBuffFromServer ( LWOOBJID objectId , const SystemAddress & sysAddr ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : DEACTIVATE_BUBBLE_BUFF_FROM_SERVER ) ;
2023-01-07 06:14:51 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST ;
SEND_PACKET ;
}
2023-03-23 14:49:31 +00:00
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleZoneSummaryDismissed ( RakNet : : BitStream & inStream , Entity * entity ) {
2023-03-25 10:26:39 +00:00
LWOOBJID player_id ;
2024-02-26 14:17:22 +00:00
inStream . Read < LWOOBJID > ( player_id ) ;
2023-07-15 20:56:33 +00:00
auto target = Game : : entityManager - > GetEntity ( player_id ) ;
2023-03-25 10:26:39 +00:00
entity - > TriggerEvent ( eTriggerEventType : : ZONE_SUMMARY_DISMISSED , target ) ;
} ;
2023-03-23 14:49:31 +00:00
void GameMessages : : SendSetNamebillboardState ( const SystemAddress & sysAddr , LWOOBJID objectId ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SET_NAME_BILLBOARD_STATE ) ;
2023-03-23 14:49:31 +00:00
// Technically these bits would be written, however the client does not
// contain a deserialize method to actually deserialize, so we are leaving it out.
// As such this GM only turns the billboard off.
// bitStream.Write(overrideDefault);
// bitStream.Write(state);
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST
else SEND_PACKET
}
void GameMessages : : SendShowBillboardInteractIcon ( const SystemAddress & sysAddr , LWOOBJID objectId ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SHOW_BILLBOARD_INTERACT_ICON ) ;
2023-03-23 14:49:31 +00:00
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) SEND_PACKET_BROADCAST
else SEND_PACKET
}
2023-05-11 00:26:04 +00:00
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleRequestActivityExit ( RakNet : : BitStream & inStream , Entity * entity ) {
2023-05-11 00:26:04 +00:00
bool canceled = false ;
2024-02-26 14:17:22 +00:00
inStream . Read ( canceled ) ;
2023-05-11 00:26:04 +00:00
if ( ! canceled ) return ;
LWOOBJID player_id = LWOOBJID_EMPTY ;
2024-02-26 14:17:22 +00:00
inStream . Read ( player_id ) ;
2023-07-15 20:56:33 +00:00
auto player = Game : : entityManager - > GetEntity ( player_id ) ;
2023-05-11 00:26:04 +00:00
if ( ! entity | | ! player ) return ;
2023-05-11 14:23:48 +00:00
entity - > RequestActivityExit ( entity , player_id , canceled ) ;
2023-05-11 00:26:04 +00:00
}
2023-08-04 02:44:03 +00:00
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleAddDonationItem ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2023-08-04 02:44:03 +00:00
uint32_t count = 1 ;
bool hasCount = false ;
2024-02-26 14:17:22 +00:00
inStream . Read ( hasCount ) ;
if ( hasCount ) inStream . Read ( count ) ;
2023-08-04 02:44:03 +00:00
LWOOBJID itemId = LWOOBJID_EMPTY ;
2024-02-26 14:17:22 +00:00
inStream . Read ( itemId ) ;
2023-08-04 02:44:03 +00:00
if ( ! itemId ) return ;
auto * donationVendorComponent = entity - > GetComponent < DonationVendorComponent > ( ) ;
if ( ! donationVendorComponent ) return ;
if ( donationVendorComponent - > GetActivityID ( ) = = 0 ) {
2023-10-21 23:31:55 +00:00
LOG ( " WARNING: Trying to dontate to a vendor with no activity " ) ;
2023-08-04 02:44:03 +00:00
return ;
}
User * user = UserManager : : Instance ( ) - > GetUser ( sysAddr ) ;
if ( ! user ) return ;
Entity * player = Game : : entityManager - > GetEntity ( user - > GetLoggedInChar ( ) ) ;
if ( ! player ) return ;
auto * characterComponent = player - > GetComponent < CharacterComponent > ( ) ;
if ( ! characterComponent ) return ;
auto * inventoryComponent = player - > GetComponent < InventoryComponent > ( ) ;
if ( ! inventoryComponent ) return ;
Item * item = inventoryComponent - > FindItemById ( itemId ) ;
if ( ! item ) return ;
if ( item - > GetCount ( ) < count ) return ;
characterComponent - > SetCurrentInteracting ( entity - > GetObjectID ( ) ) ;
inventoryComponent - > MoveItemToInventory ( item , eInventoryType : : DONATION , count , true , false , true ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleRemoveDonationItem ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
2023-08-04 02:44:03 +00:00
bool confirmed = false ;
2024-02-26 14:17:22 +00:00
inStream . Read ( confirmed ) ;
2023-08-04 02:44:03 +00:00
uint32_t count = 1 ;
bool hasCount = false ;
2024-02-26 14:17:22 +00:00
inStream . Read ( hasCount ) ;
if ( hasCount ) inStream . Read ( count ) ;
2023-08-04 02:44:03 +00:00
LWOOBJID itemId = LWOOBJID_EMPTY ;
2024-02-26 14:17:22 +00:00
inStream . Read ( itemId ) ;
2023-08-04 02:44:03 +00:00
if ( ! itemId ) return ;
User * user = UserManager : : Instance ( ) - > GetUser ( sysAddr ) ;
if ( ! user ) return ;
Entity * player = Game : : entityManager - > GetEntity ( user - > GetLoggedInChar ( ) ) ;
if ( ! player ) return ;
auto * inventoryComponent = player - > GetComponent < InventoryComponent > ( ) ;
if ( ! inventoryComponent ) return ;
Item * item = inventoryComponent - > FindItemById ( itemId ) ;
if ( ! item ) return ;
if ( item - > GetCount ( ) < count ) return ;
inventoryComponent - > MoveItemToInventory ( item , eInventoryType : : BRICKS , count , true , false , true ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleConfirmDonationOnPlayer ( RakNet : : BitStream & inStream , Entity * entity ) {
2023-08-04 02:44:03 +00:00
auto * inventoryComponent = entity - > GetComponent < InventoryComponent > ( ) ;
if ( ! inventoryComponent ) return ;
auto * missionComponent = entity - > GetComponent < MissionComponent > ( ) ;
if ( ! missionComponent ) return ;
auto * characterComponent = entity - > GetComponent < CharacterComponent > ( ) ;
if ( ! characterComponent | | ! characterComponent - > GetCurrentInteracting ( ) ) return ;
auto * donationEntity = Game : : entityManager - > GetEntity ( characterComponent - > GetCurrentInteracting ( ) ) ;
if ( ! donationEntity ) return ;
auto * donationVendorComponent = donationEntity - > GetComponent < DonationVendorComponent > ( ) ;
2023-10-16 12:55:57 +00:00
if ( ! donationVendorComponent ) return ;
2023-08-04 02:44:03 +00:00
if ( donationVendorComponent - > GetActivityID ( ) = = 0 ) {
2023-10-21 23:31:55 +00:00
LOG ( " WARNING: Trying to dontate to a vendor with no activity " ) ;
2023-08-04 02:44:03 +00:00
return ;
}
auto * inventory = inventoryComponent - > GetInventory ( eInventoryType : : DONATION ) ;
if ( ! inventory ) return ;
auto items = inventory - > GetItems ( ) ;
if ( ! items . empty ( ) ) {
uint32_t count = 0 ;
2023-10-16 12:55:57 +00:00
for ( auto & [ itemID , item ] : items ) {
2023-08-04 02:44:03 +00:00
count + = item - > GetCount ( ) ;
item - > RemoveFromInventory ( ) ;
}
missionComponent - > Progress ( eMissionTaskType : : DONATION , 0 , LWOOBJID_EMPTY , " " , count ) ;
LeaderboardManager : : SaveScore ( entity - > GetObjectID ( ) , donationVendorComponent - > GetActivityID ( ) , count ) ;
donationVendorComponent - > SubmitDonation ( count ) ;
Game : : entityManager - > SerializeEntity ( donationEntity ) ;
}
characterComponent - > SetCurrentInteracting ( LWOOBJID_EMPTY ) ;
}
2024-02-26 14:17:22 +00:00
void GameMessages : : HandleCancelDonationOnPlayer ( RakNet : : BitStream & inStream , Entity * entity ) {
2023-08-04 02:44:03 +00:00
auto * inventoryComponent = entity - > GetComponent < InventoryComponent > ( ) ;
if ( ! inventoryComponent ) return ;
auto * inventory = inventoryComponent - > GetInventory ( eInventoryType : : DONATION ) ;
if ( ! inventory ) return ;
auto items = inventory - > GetItems ( ) ;
2023-10-16 12:55:57 +00:00
for ( auto & [ itemID , item ] : items ) {
2023-08-04 02:44:03 +00:00
inventoryComponent - > MoveItemToInventory ( item , eInventoryType : : BRICKS , item - > GetCount ( ) , false , false , true ) ;
}
auto * characterComponent = entity - > GetComponent < CharacterComponent > ( ) ;
if ( ! characterComponent ) return ;
characterComponent - > SetCurrentInteracting ( LWOOBJID_EMPTY ) ;
}
2024-04-08 20:11:59 +00:00
void GameMessages : : SendSlashCommandFeedbackText ( Entity * entity , std : : u16string text ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : SLASH_COMMAND_TEXT_FEEDBACK ) ;
2024-04-08 20:11:59 +00:00
bitStream . Write < uint32_t > ( text . size ( ) ) ;
bitStream . Write ( text ) ;
auto sysAddr = entity - > GetSystemAddress ( ) ;
SEND_PACKET ;
}
2024-06-04 02:50:12 +00:00
2024-08-02 06:38:21 +00:00
void GameMessages : : HandleUpdateInventoryGroup ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
std : : string action ;
std : : u16string groupName ;
InventoryComponent : : GroupUpdate groupUpdate ;
bool locked { } ; // All groups are locked by default
uint32_t size { } ;
if ( ! inStream . Read ( size ) ) return ;
action . resize ( size ) ;
if ( ! inStream . Read ( action . data ( ) , size ) ) return ;
if ( ! inStream . Read ( size ) ) return ;
groupUpdate . groupId . resize ( size ) ;
if ( ! inStream . Read ( groupUpdate . groupId . data ( ) , size ) ) return ;
if ( ! inStream . Read ( size ) ) return ;
groupName . resize ( size ) ;
if ( ! inStream . Read ( reinterpret_cast < char * > ( groupName . data ( ) ) , size * 2 ) ) return ;
if ( ! inStream . Read ( groupUpdate . inventory ) ) return ;
if ( ! inStream . Read ( locked ) ) return ;
groupUpdate . groupName = GeneralUtils : : UTF16ToWTF8 ( groupName ) ;
if ( action = = " ADD " ) groupUpdate . command = InventoryComponent : : GroupUpdateCommand : : ADD ;
else if ( action = = " MODIFY " ) groupUpdate . command = InventoryComponent : : GroupUpdateCommand : : MODIFY ;
else if ( action = = " REMOVE " ) groupUpdate . command = InventoryComponent : : GroupUpdateCommand : : REMOVE ;
else {
LOG ( " Invalid action %s " , action . c_str ( ) ) ;
return ;
}
auto * inventoryComponent = entity - > GetComponent < InventoryComponent > ( ) ;
if ( inventoryComponent ) inventoryComponent - > UpdateGroup ( groupUpdate ) ;
}
void GameMessages : : HandleUpdateInventoryGroupContents ( RakNet : : BitStream & inStream , Entity * entity , const SystemAddress & sysAddr ) {
std : : string action ;
InventoryComponent : : GroupUpdate groupUpdate ;
uint32_t size { } ;
if ( ! inStream . Read ( size ) ) return ;
action . resize ( size ) ;
if ( ! inStream . Read ( action . data ( ) , size ) ) return ;
if ( action = = " ADD " ) groupUpdate . command = InventoryComponent : : GroupUpdateCommand : : ADD_LOT ;
else if ( action = = " REMOVE " ) groupUpdate . command = InventoryComponent : : GroupUpdateCommand : : REMOVE_LOT ;
else {
LOG ( " Invalid action %s " , action . c_str ( ) ) ;
return ;
}
if ( ! inStream . Read ( size ) ) return ;
groupUpdate . groupId . resize ( size ) ;
if ( ! inStream . Read ( groupUpdate . groupId . data ( ) , size ) ) return ;
if ( ! inStream . Read ( groupUpdate . inventory ) ) return ;
if ( ! inStream . Read ( groupUpdate . lot ) ) return ;
auto * inventoryComponent = entity - > GetComponent < InventoryComponent > ( ) ;
if ( inventoryComponent ) inventoryComponent - > UpdateGroup ( groupUpdate ) ;
}
2024-06-04 02:50:12 +00:00
void GameMessages : : SendForceCameraTargetCycle ( Entity * entity , bool bForceCycling , eCameraTargetCyclingMode cyclingMode , LWOOBJID optionalTargetID ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( entity - > GetObjectID ( ) ) ;
2024-11-18 00:39:44 +00:00
bitStream . Write ( MessageType : : Game : : FORCE_CAMERA_TARGET_CYCLE ) ;
2024-06-04 02:50:12 +00:00
bitStream . Write ( bForceCycling ) ;
2024-06-04 03:30:57 +00:00
bitStream . Write ( cyclingMode ! = eCameraTargetCyclingMode : : ALLOW_CYCLE_TEAMMATES ) ;
if ( cyclingMode ! = eCameraTargetCyclingMode : : ALLOW_CYCLE_TEAMMATES ) bitStream . Write ( cyclingMode ) ;
2024-06-04 02:50:12 +00:00
bitStream . Write ( optionalTargetID ) ;
auto sysAddr = entity - > GetSystemAddress ( ) ;
SEND_PACKET ;
}
2024-12-11 03:10:54 +00:00
void GameMessages : : SendUpdateInventoryUi ( LWOOBJID objectId , const SystemAddress & sysAddr ) {
CBITSTREAM ;
CMSGHEADER ;
bitStream . Write ( objectId ) ;
bitStream . Write ( MessageType : : Game : : UPDATE_INVENTORY_UI ) ;
2024-12-16 19:35:36 +00:00
SEND_PACKET ;
}
2024-12-18 03:04:35 +00:00
namespace GameMessages {
void GameMsg : : Send ( const SystemAddress & sysAddr ) const {
CBITSTREAM ;
CMSGHEADER ;
2024-12-16 19:35:36 +00:00
2024-12-18 03:04:35 +00:00
bitStream . Write ( target ) ; // Who this message will be sent to on the (a) client
bitStream . Write ( msgId ) ; // the ID of this message
2024-12-16 19:35:36 +00:00
2024-12-18 03:04:35 +00:00
Serialize ( bitStream ) ; // write the message data
// Send to everyone if someone sent unassigned system address, or to one specific client.
if ( sysAddr = = UNASSIGNED_SYSTEM_ADDRESS ) {
SEND_PACKET_BROADCAST ;
} else {
SEND_PACKET ;
}
}
void DisplayTooltip : : Serialize ( RakNet : : BitStream & bitStream ) const {
bitStream . Write ( doOrDie ) ;
bitStream . Write ( noRepeat ) ;
bitStream . Write ( noRevive ) ;
bitStream . Write ( isPropertyTooltip ) ;
bitStream . Write ( show ) ;
bitStream . Write ( translate ) ;
bitStream . Write ( time ) ;
bitStream . Write < int32_t > ( id . size ( ) ) ;
bitStream . Write ( id ) ;
std : : string toWrite ;
for ( const auto * item : localizeParams ) {
toWrite + = item - > GetString ( ) + " \n " ;
}
if ( ! toWrite . empty ( ) ) toWrite . pop_back ( ) ;
bitStream . Write < int32_t > ( toWrite . size ( ) ) ;
bitStream . Write ( GeneralUtils : : ASCIIToUTF16 ( toWrite ) ) ;
if ( ! toWrite . empty ( ) ) bitStream . Write < uint16_t > ( 0x00 ) ; // Null Terminator
bitStream . Write < int32_t > ( imageName . size ( ) ) ;
bitStream . Write ( imageName ) ;
bitStream . Write < int32_t > ( text . size ( ) ) ;
bitStream . Write ( text ) ;
}
void UseItemOnClient : : Serialize ( RakNet : : BitStream & bitStream ) const {
bitStream . Write ( itemLOT ) ;
bitStream . Write ( itemToUse ) ;
bitStream . Write ( itemType ) ;
bitStream . Write ( playerId ) ;
bitStream . Write ( targetPosition . x ) ;
bitStream . Write ( targetPosition . y ) ;
bitStream . Write ( targetPosition . z ) ;
}
2024-12-11 03:10:54 +00:00
}