2010-11-09 10:15:35 -05:00
/*
2020-01-02 06:44:10 +01:00
* This file is part of the TrinityCore Project. See AUTHORS file for Copyright information
2010-11-09 10:15:35 -05:00
*
* This program is free software; you can redistribute it and/or modify it
* under the terms of the GNU General Public License as published by the
* Free Software Foundation; either version 2 of the License, or (at your
* option) any later version.
*
* This program is distributed in the hope that it will be useful, but WITHOUT
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
* more details.
*
* You should have received a copy of the GNU General Public License along
* with this program. If not, see <http://www.gnu.org/licenses/>.
*/
/* ScriptData
Name: debug_commandscript
%Complete: 100
Comment: All debug related commands
Category: commandscripts
EndScriptData */
2017-05-20 00:09:37 +02:00
#include "ScriptMgr.h"
2017-06-04 01:00:45 +02:00
#include "Bag.h"
2016-06-14 18:23:45 +02:00
#include "BattlefieldMgr.h"
2010-11-09 10:15:35 -05:00
#include "BattlegroundMgr.h"
2010-11-14 00:13:51 +01:00
#include "CellImpl.h"
2020-09-10 01:05:44 +02:00
#include "Channel.h"
2018-08-25 20:13:19 +02:00
#include "ChannelPackets.h"
2017-05-18 23:52:58 +02:00
#include "Chat.h"
2022-02-11 21:57:45 +01:00
#include "ChatCommand.h"
2017-05-20 00:09:37 +02:00
#include "ChatPackets.h"
2017-05-14 11:40:55 +02:00
#include "Conversation.h"
2022-02-13 00:49:10 +01:00
#include "CreatureAI.h"
2021-10-02 19:59:56 +02:00
#include "DB2Stores.h"
2019-07-16 15:04:14 +02:00
#include "GameTime.h"
2010-11-14 00:13:51 +01:00
#include "GridNotifiersImpl.h"
2018-01-24 22:52:42 +01:00
#include "InstanceScript.h"
2012-11-20 12:30:30 +01:00
#include "Language.h"
2017-05-18 23:52:58 +02:00
#include "Log.h"
#include "M2Stores.h"
2015-08-16 16:39:02 +02:00
#include "MapManager.h"
2015-03-27 22:21:24 +01:00
#include "MovementPackets.h"
2018-01-09 18:09:24 +01:00
#include "ObjectAccessor.h"
2017-05-18 23:52:58 +02:00
#include "ObjectMgr.h"
2018-01-28 11:37:20 +01:00
#include "PhasingHandler.h"
2019-08-04 12:22:57 +02:00
#include "PoolMgr.h"
2017-05-20 00:09:37 +02:00
#include "RBAC.h"
2018-01-09 18:09:24 +01:00
#include "SpellMgr.h"
2015-07-19 00:31:11 +02:00
#include "SpellPackets.h"
2017-05-18 23:52:58 +02:00
#include "Transport.h"
2020-08-19 00:25:44 +02:00
#include "Warden.h"
2018-10-23 16:20:45 +02:00
#include "World.h"
2017-06-04 01:00:45 +02:00
#include "WorldSession.h"
2010-11-13 22:29:46 +01:00
#include <fstream>
2016-06-14 18:23:45 +02:00
#include <limits>
2018-01-25 13:45:11 +01:00
#include <map>
#include <set>
2020-04-03 18:12:07 +02:00
#include <sstream>
2010-11-09 10:15:35 -05:00
2019-07-16 15:04:14 +02:00
using namespace Trinity :: ChatCommands ;
2020-09-20 02:50:38 +02:00
2010-11-09 10:15:35 -05:00
class debug_commandscript : public CommandScript
{
2010-11-19 14:04:21 +01:00
public :
debug_commandscript () : CommandScript ( "debug_commandscript" ) { }
2010-11-09 10:15:35 -05:00
2020-09-20 02:50:38 +02:00
ChatCommandTable GetCommands () const override
2010-11-19 14:04:21 +01:00
{
2020-09-20 02:50:38 +02:00
static ChatCommandTable debugPlayCommandTable =
2019-04-27 18:39:06 +02:00
{
2020-09-20 02:50:38 +02:00
{ "cinematic" , HandleDebugPlayCinematicCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "movie" , HandleDebugPlayMovieCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "sound" , HandleDebugPlaySoundCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "music" , HandleDebugPlayMusicCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
2023-08-13 23:59:05 +02:00
{ "objectsound" , HandleDebugPlayObjectSoundCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
2019-04-27 18:39:06 +02:00
};
2020-09-20 02:50:38 +02:00
static ChatCommandTable debugSendCommandTable =
2020-08-19 00:25:44 +02:00
{
2020-09-20 02:50:38 +02:00
{ "buyerror" , HandleDebugSendBuyErrorCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "channelnotify" , HandleDebugSendChannelNotifyCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "chatmessage" , HandleDebugSendChatMsgCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "equiperror" , HandleDebugSendEquipErrorCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "largepacket" , HandleDebugSendLargePacketCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "opcode" , HandleDebugSendOpcodeCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "qpartymsg" , HandleDebugSendQuestPartyMsgCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "qinvalidmsg" , HandleDebugSendQuestInvalidMsgCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "sellerror" , HandleDebugSendSellErrorCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "setphaseshift" , HandleDebugSendSetPhaseShiftCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "spellfail" , HandleDebugSendSpellFailCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "playerchoice" , HandleDebugSendPlayerChoiceCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
2020-08-19 00:25:44 +02:00
};
2020-09-20 02:50:38 +02:00
static ChatCommandTable debugCommandTable =
2010-11-19 14:04:21 +01:00
{
2020-09-20 02:50:38 +02:00
{ "threat" , HandleDebugThreatListCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "threatinfo" , HandleDebugThreatInfoCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "combat" , HandleDebugCombatListCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "anim" , HandleDebugAnimCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "arena" , HandleDebugArenaCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: Yes },
{ "bg" , HandleDebugBattlegroundCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: Yes },
{ "getitemstate" , HandleDebugGetItemStateCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "lootrecipient" , HandleDebugGetLootRecipientCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "play" , debugPlayCommandTable },
{ "send" , debugSendCommandTable },
{ "setaurastate" , HandleDebugSetAuraStateCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "spawnvehicle" , HandleDebugSpawnVehicleCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "entervehicle" , HandleDebugEnterVehicleCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "worldstate" , HandleDebugUpdateWorldStateCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "itemexpire" , HandleDebugItemExpireCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "areatriggers" , HandleDebugAreaTriggersCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "los" , HandleDebugLoSCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "moveflags" , HandleDebugMoveflagsCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "transport" , HandleDebugTransportCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
2020-09-26 16:23:26 +02:00
{ "loadcells" , HandleDebugLoadCellsCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: Yes },
2020-09-20 02:50:38 +02:00
{ "phase" , HandleDebugPhaseCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "boundary" , HandleDebugBoundaryCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "raidreset" , HandleDebugRaidResetCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "neargraveyard" , HandleDebugNearGraveyard , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "instancespawn" , HandleDebugInstanceSpawns , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
2023-05-26 23:51:20 +02:00
{ "conversation" , HandleDebugConversationCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "wsexpression" , HandleDebugWSExpressionCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "playercondition" , HandleDebugPlayerConditionCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
2020-09-20 02:50:38 +02:00
{ "pvp warmode" , HandleDebugWarModeBalanceCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: Yes },
{ "dummy" , HandleDebugDummyCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
{ "asan memoryleak" , HandleDebugMemoryLeak , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: Yes },
{ "asan outofbounds" , HandleDebugOutOfBounds , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: Yes },
{ "guidlimits" , HandleDebugGuidLimitsCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: Yes },
{ "objectcount" , HandleDebugObjectCountCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: Yes },
{ "questreset" , HandleDebugQuestResetCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: Yes },
{ "warden force" , HandleDebugWardenForce , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: Yes },
{ "personalclone" , HandleDebugBecomePersonalClone , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No }
2010-11-19 14:04:21 +01:00
};
2020-09-20 02:50:38 +02:00
static ChatCommandTable commandTable =
2010-11-19 14:04:21 +01:00
{
2020-09-20 02:50:38 +02:00
{ "debug" , debugCommandTable },
{ "wpgps" , HandleWPGPSCommand , rbac :: RBAC_PERM_COMMAND_DEBUG , Console :: No },
2010-11-19 14:04:21 +01:00
};
return commandTable ;
}
2010-11-09 10:15:35 -05:00
2021-12-26 20:14:46 +02:00
static bool TryExtractTeamId ( std :: string const & args , TeamId & outFaction )
{
if ( "a" == args || "alliance" == args )
outFaction = TEAM_ALLIANCE ;
else if ( "h" == args || "horde" == args )
outFaction = TEAM_HORDE ;
else if ( "n" == args || "neutral" == args )
outFaction = TEAM_NEUTRAL ;
else
return false ;
return true ;
}
2020-09-20 02:50:38 +02:00
static bool HandleDebugWarModeBalanceCommand ( ChatHandler * handler , Variant < uint32 , EXACT_SEQUENCE ( "alliance" ), EXACT_SEQUENCE ( "horde" ), EXACT_SEQUENCE ( "neutral" ), EXACT_SEQUENCE ( "off" ) > command , Optional < int32 > rewardValue )
2021-12-26 20:14:46 +02:00
{
// USAGE: .debug pvp fb <alliance|horde|neutral|off> [pct]
// neutral Sets faction balance off.
// alliance Set faction balance to alliance.
// horde Set faction balance to horde.
// off Reset the faction balance and use the calculated value of it
2020-08-17 02:23:38 +02:00
switch ( command . index ())
2021-12-26 20:14:46 +02:00
{
case 0 : // workaround for Variant of only ExactSequences not being supported
handler -> SendSysMessage ( LANG_BAD_VALUE );
handler -> SetSentErrorMessage ( true );
return false ;
case 1 :
2022-01-23 20:31:52 +01:00
sWorld -> SetForcedWarModeFactionBalanceState ( TEAM_ALLIANCE , rewardValue . value_or ( 0 ));
2021-12-26 20:14:46 +02:00
break ;
case 2 :
2022-01-23 20:31:52 +01:00
sWorld -> SetForcedWarModeFactionBalanceState ( TEAM_HORDE , rewardValue . value_or ( 0 ));
2021-12-26 20:14:46 +02:00
break ;
case 3 :
sWorld -> SetForcedWarModeFactionBalanceState ( TEAM_NEUTRAL );
break ;
case 4 :
sWorld -> DisableForcedWarModeFactionBalanceState ();
break ;
}
return true ;
}
2020-08-17 22:45:09 +02:00
// cinematicId - ID from CinematicSequences.dbc
static bool HandleDebugPlayCinematicCommand ( ChatHandler * handler , uint32 cinematicId )
2010-11-19 14:04:21 +01:00
{
2017-05-26 10:52:56 +04:00
CinematicSequencesEntry const * cineSeq = sCinematicSequencesStore . LookupEntry ( cinematicId );
2016-04-27 16:53:18 +02:00
if ( ! cineSeq )
2010-11-19 14:04:21 +01:00
{
2017-05-26 10:52:56 +04:00
handler -> PSendSysMessage ( LANG_CINEMATIC_NOT_EXIST , cinematicId );
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2016-04-27 16:53:18 +02:00
// Dump camera locations
2017-04-17 00:03:44 +02:00
if ( std :: vector < FlyByCamera > const * flyByCameras = GetFlyByCameras ( cineSeq -> Camera [ 0 ]))
2016-04-27 16:53:18 +02:00
{
2017-05-26 10:52:56 +04:00
handler -> PSendSysMessage ( "Waypoints for sequence %u, camera %u" , cinematicId , cineSeq -> Camera [ 0 ]);
2016-04-27 16:53:18 +02:00
uint32 count = 1 ;
2017-04-17 00:03:44 +02:00
for ( FlyByCamera const & cam : * flyByCameras )
2016-04-27 16:53:18 +02:00
{
2017-05-16 22:16:21 +02:00
handler -> PSendSysMessage ( "%02u - %7ums [%s (%f degrees)]" , count , cam . timeStamp , cam . locations . ToString (). c_str (), cam . locations . GetOrientation () * ( 180 / M_PI ));
2020-09-04 13:38:24 +02:00
++ count ;
2016-04-27 16:53:18 +02:00
}
2017-04-17 00:03:44 +02:00
handler -> PSendSysMessage ( SZFMTD " waypoints dumped" , flyByCameras -> size ());
2016-04-27 16:53:18 +02:00
}
2020-09-10 01:05:44 +02:00
handler -> GetPlayer () -> SendCinematicStart ( cinematicId );
2010-11-19 14:04:21 +01:00
return true ;
}
2020-08-17 22:45:09 +02:00
// movieId - ID from Movie.dbc
static bool HandleDebugPlayMovieCommand ( ChatHandler * handler , uint32 movieId )
2010-11-19 14:04:21 +01:00
{
2010-11-09 10:15:35 -05:00
2017-05-26 10:52:56 +04:00
if ( ! sMovieStore . LookupEntry ( movieId ))
2010-11-19 14:04:21 +01:00
{
2017-05-26 10:52:56 +04:00
handler -> PSendSysMessage ( LANG_MOVIE_NOT_EXIST , movieId );
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2020-09-10 01:05:44 +02:00
handler -> GetPlayer () -> SendMovieStart ( movieId );
2010-11-19 14:04:21 +01:00
return true ;
}
2020-08-17 22:45:09 +02:00
// soundId - ID from SoundKit.db2
static bool HandleDebugPlaySoundCommand ( ChatHandler * handler , uint32 soundId , Optional < uint32 > broadcastTextId )
2010-11-19 14:04:21 +01:00
{
2016-01-24 15:56:10 +01:00
if ( ! sSoundKitStore . LookupEntry ( soundId ))
2010-11-09 10:15:35 -05:00
{
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_SOUND_NOT_EXIST , soundId );
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2020-09-10 01:05:44 +02:00
Player * player = handler -> GetPlayer ();
2017-05-26 10:52:56 +04:00
2010-11-19 14:04:21 +01:00
Unit * unit = handler -> getSelectedUnit ();
if ( ! unit )
{
handler -> SendSysMessage ( LANG_SELECT_CHAR_OR_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2017-05-26 10:52:56 +04:00
if ( player -> GetTarget (). IsEmpty ())
unit -> PlayDistanceSound ( soundId , player );
2010-11-19 14:04:21 +01:00
else
2020-08-17 22:45:09 +02:00
unit -> PlayDirectSound ( soundId , player , broadcastTextId . value_or ( 0 ));
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
handler -> PSendSysMessage ( LANG_YOU_HEAR_SOUND , soundId );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
// musicId - ID from SoundEntries.dbc
static bool HandleDebugPlayMusicCommand ( ChatHandler * handler , uint32 musicId )
2017-05-26 10:52:56 +04:00
{
if ( ! sSoundKitStore . LookupEntry ( musicId ))
{
handler -> PSendSysMessage ( LANG_SOUND_NOT_EXIST , musicId );
handler -> SetSentErrorMessage ( true );
return false ;
}
2020-09-10 01:05:44 +02:00
Player * player = handler -> GetPlayer ();
2017-05-26 10:52:56 +04:00
player -> PlayDirectMusic ( musicId , player );
handler -> PSendSysMessage ( LANG_YOU_HEAR_SOUND , musicId );
return true ;
}
2023-08-13 23:59:05 +02:00
static bool HandleDebugPlayObjectSoundCommand ( ChatHandler * handler , int32 soundKitId , Optional < int32 > broadcastTextId )
{
if ( ! sSoundKitStore . LookupEntry ( soundKitId ))
{
handler -> PSendSysMessage ( LANG_SOUND_NOT_EXIST , soundKitId );
handler -> SetSentErrorMessage ( true );
return false ;
}
Player * player = handler -> GetPlayer ();
player -> PlayObjectSound ( soundKitId , player -> GetGUID (), player , broadcastTextId . has_value () ? * broadcastTextId : 0 );
handler -> PSendSysMessage ( LANG_YOU_HEAR_SOUND , soundKitId );
return true ;
}
2020-09-10 01:05:44 +02:00
static bool HandleDebugSendSpellFailCommand ( ChatHandler * handler , SpellCastResult result , Optional < int32 > failArg1 , Optional < int32 > failArg2 )
2010-11-19 14:04:21 +01:00
{
2016-06-05 14:08:53 +02:00
WorldPackets :: Spells :: CastFailed castFailed ;
2016-06-03 16:49:42 +02:00
castFailed . CastID = ObjectGuid :: Empty ;
2015-07-19 00:31:11 +02:00
castFailed . SpellID = 133 ;
2020-09-10 01:05:44 +02:00
castFailed . Reason = result ;
castFailed . FailedArg1 = failArg1 . value_or ( - 1 );
castFailed . FailedArg2 = failArg2 . value_or ( - 1 );
2015-07-19 00:31:11 +02:00
handler -> GetSession () -> SendPacket ( castFailed . Write ());
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2017-12-17 14:40:04 +01:00
2020-09-10 01:05:44 +02:00
static bool HandleDebugSendPlayerChoiceCommand ( ChatHandler * handler , int32 choiceId )
{
Player * player = handler -> GetPlayer ();
2017-12-17 14:40:04 +01:00
player -> SendPlayerChoice ( player -> GetGUID (), choiceId );
return true ;
}
2020-09-10 01:05:44 +02:00
static bool HandleDebugSendEquipErrorCommand ( ChatHandler * handler , InventoryResult error )
2010-11-19 14:04:21 +01:00
{
2020-09-10 01:05:44 +02:00
handler -> GetPlayer () -> SendEquipError ( error , nullptr , nullptr );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-09-10 01:05:44 +02:00
static bool HandleDebugSendSellErrorCommand ( ChatHandler * handler , SellResult error )
2010-11-19 14:04:21 +01:00
{
2020-09-10 01:05:44 +02:00
handler -> GetPlayer () -> SendSellError ( error , nullptr , ObjectGuid :: Empty );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-09-10 01:05:44 +02:00
static bool HandleDebugSendBuyErrorCommand ( ChatHandler * handler , BuyResult error )
2010-11-19 14:04:21 +01:00
{
2020-09-10 01:05:44 +02:00
handler -> GetPlayer () -> SendBuyError ( error , nullptr , 0 , 0 );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
static bool HandleDebugSendOpcodeCommand ( ChatHandler * handler )
2010-11-19 14:04:21 +01:00
{
2011-06-30 14:24:56 +02:00
Unit * unit = handler -> getSelectedUnit ();
2020-08-14 17:06:03 +02:00
Player * player = nullptr ;
2010-11-19 14:04:21 +01:00
if ( ! unit || ( unit -> GetTypeId () != TYPEID_PLAYER ))
2020-09-10 01:05:44 +02:00
player = handler -> GetPlayer ();
2010-11-19 14:04:21 +01:00
else
2013-07-20 21:52:05 +02:00
player = unit -> ToPlayer ();
2011-10-10 10:33:13 -03:00
if ( ! unit )
unit = player ;
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
std :: ifstream ifs ( "opcode.txt" );
2013-09-06 15:31:22 +02:00
if ( ifs . fail ())
2010-11-19 14:04:21 +01:00
return false ;
2010-11-09 10:15:35 -05:00
2011-09-01 10:46:15 +02:00
// remove comments from file
std :: stringstream parsedStream ;
while ( ! ifs . eof ())
{
2021-01-24 16:04:47 +01:00
char commentToken [ 2 ] = {};
2011-09-01 10:46:15 +02:00
ifs . get ( commentToken [ 0 ]);
2021-01-24 16:04:47 +01:00
if ( ifs . eof ())
break ;
if ( commentToken [ 0 ] == '/' )
2011-09-01 10:46:15 +02:00
{
ifs . get ( commentToken [ 1 ]);
2021-01-24 16:04:47 +01:00
if ( ! ifs . eof ())
2011-09-01 10:46:15 +02:00
{
2021-01-24 16:04:47 +01:00
// /* comment
if ( commentToken [ 1 ] == '*' )
2011-09-01 10:46:15 +02:00
{
2021-01-24 16:04:47 +01:00
while ( ! ifs . eof ())
2011-09-01 10:46:15 +02:00
{
2021-01-24 16:04:47 +01:00
ifs . get ( commentToken [ 0 ]);
if ( ifs . eof ())
2011-09-01 10:46:15 +02:00
break ;
2021-01-24 16:04:47 +01:00
if ( commentToken [ 0 ] == '*' )
{
ifs . get ( commentToken [ 1 ]);
if ( ifs . eof ())
break ;
if ( commentToken [ 1 ] == '/' )
break ;
else
ifs . putback ( commentToken [ 1 ]);
}
2011-09-01 10:46:15 +02:00
}
2021-01-24 16:04:47 +01:00
continue ;
2011-09-01 10:46:15 +02:00
}
2021-01-24 16:04:47 +01:00
// line comment
else if ( commentToken [ 1 ] == '/' )
{
std :: string str ;
std :: getline ( ifs , str );
if ( ifs . eof ())
break ;
continue ;
}
// regular data
else
ifs . putback ( commentToken [ 1 ]);
2011-09-01 10:46:15 +02:00
}
}
parsedStream . put ( commentToken [ 0 ]);
}
ifs . close ();
2021-01-24 16:04:47 +01:00
uint32 opcode = 0 ;
2011-09-01 10:46:15 +02:00
parsedStream >> opcode ;
2010-11-09 10:15:35 -05:00
2021-01-24 16:04:47 +01:00
if ( ! opcode )
return false ;
2014-10-25 15:41:42 +01:00
WorldPacket data ( OpcodeServer ( opcode ), 0 );
2010-11-09 10:15:35 -05:00
2021-01-24 16:04:47 +01:00
while ( ! parsedStream . eof () && ! parsedStream . fail ())
2010-11-19 14:04:21 +01:00
{
std :: string type ;
2011-09-01 10:46:15 +02:00
parsedStream >> type ;
2010-11-09 10:15:35 -05:00
2014-09-19 03:30:02 +01:00
if ( type . empty ())
2010-11-19 14:04:21 +01:00
break ;
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( type == "uint8" )
2010-11-09 10:15:35 -05:00
{
2021-01-24 16:04:47 +01:00
if ( parsedStream . eof ())
return false ;
uint16 val1 = 0 ;
2011-09-01 10:46:15 +02:00
parsedStream >> val1 ;
2021-01-24 16:04:47 +01:00
if ( parsedStream . fail ())
return false ;
2010-11-19 14:04:21 +01:00
data << uint8 ( val1 );
}
else if ( type == "uint16" )
{
2021-01-24 16:04:47 +01:00
if ( parsedStream . eof ())
return false ;
uint16 val2 = 0 ;
2011-09-01 10:46:15 +02:00
parsedStream >> val2 ;
2021-01-24 16:04:47 +01:00
if ( parsedStream . fail ())
return false ;
2010-11-19 14:04:21 +01:00
data << val2 ;
}
else if ( type == "uint32" )
{
2021-01-24 16:04:47 +01:00
if ( parsedStream . eof ())
return false ;
uint32 val3 = 0 ;
2011-09-01 10:46:15 +02:00
parsedStream >> val3 ;
2021-01-24 16:04:47 +01:00
if ( parsedStream . fail ())
return false ;
2010-11-19 14:04:21 +01:00
data << val3 ;
}
else if ( type == "uint64" )
{
2021-01-24 16:04:47 +01:00
if ( parsedStream . eof ())
return false ;
uint64 val4 = 0 ;
2011-09-01 10:46:15 +02:00
parsedStream >> val4 ;
2021-01-24 16:04:47 +01:00
if ( parsedStream . fail ())
return false ;
2010-11-19 14:04:21 +01:00
data << val4 ;
}
else if ( type == "float" )
{
2021-01-24 16:04:47 +01:00
if ( parsedStream . eof ())
return false ;
float val5 = 0.0f ;
2011-09-01 10:46:15 +02:00
parsedStream >> val5 ;
2021-01-24 16:04:47 +01:00
if ( parsedStream . fail ())
return false ;
2010-11-19 14:04:21 +01:00
data << val5 ;
}
else if ( type == "string" )
{
std :: string val6 ;
2011-09-01 10:46:15 +02:00
parsedStream >> val6 ;
2021-01-24 16:04:47 +01:00
// empty string is allowed so no need to check eof/fail here
2010-11-19 14:04:21 +01:00
data << val6 ;
}
else if ( type == "goguid" )
{
2011-06-30 14:24:56 +02:00
GameObject * obj = handler -> GetNearbyGameObject ();
2010-11-19 14:04:21 +01:00
if ( ! obj )
2010-11-09 10:15:35 -05:00
{
2017-07-22 10:22:17 +03:00
handler -> PSendSysMessage ( LANG_COMMAND_OBJNOTFOUND , "0" );
2010-11-19 14:04:21 +01:00
handler -> SetSentErrorMessage ( true );
return false ;
2010-11-09 10:15:35 -05:00
}
2014-10-21 19:23:32 +02:00
data << obj -> GetGUID ();
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
else if ( type == "myguid" )
2010-11-09 10:15:35 -05:00
{
2014-10-21 19:23:32 +02:00
data << player -> GetGUID ();
2010-11-19 14:04:21 +01:00
}
else if ( type == "itsguid" )
{
2014-10-21 19:23:32 +02:00
data << unit -> GetGUID ();
2010-11-19 14:04:21 +01:00
}
2011-09-01 10:46:15 +02:00
else if ( type == "itspos" )
2010-11-19 14:04:21 +01:00
{
data << unit -> GetPositionX ();
data << unit -> GetPositionY ();
data << unit -> GetPositionZ ();
}
else if ( type == "mypos" )
{
data << player -> GetPositionX ();
data << player -> GetPositionY ();
data << player -> GetPositionZ ();
}
else
{
2023-01-08 21:16:53 +01:00
TC_LOG_ERROR ( "misc" , "Sending opcode that has unknown type '{}'" , type );
2010-11-19 14:04:21 +01:00
break ;
2010-11-09 10:15:35 -05:00
}
}
2023-01-08 21:16:53 +01:00
TC_LOG_DEBUG ( "network" , "Sending opcode {}" , data . GetOpcode ());
2010-11-19 14:04:21 +01:00
data . hexlike ();
2012-08-03 18:54:37 +01:00
player -> GetSession () -> SendPacket ( & data , true );
2012-10-24 13:29:34 +02:00
handler -> PSendSysMessage ( LANG_COMMAND_OPCODESENT , data . GetOpcode (), unit -> GetName (). c_str ());
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
static bool HandleDebugUpdateWorldStateCommand ( ChatHandler * handler , uint32 variable , uint32 value )
2010-11-19 14:04:21 +01:00
{
2020-09-10 01:05:44 +02:00
handler -> GetPlayer () -> SendUpdateWorldState ( variable , value );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
static bool HandleDebugAreaTriggersCommand ( ChatHandler * handler )
2010-11-19 14:04:21 +01:00
{
2020-09-10 01:05:44 +02:00
Player * player = handler -> GetPlayer ();
2011-07-01 03:00:39 +02:00
if ( ! player -> isDebugAreaTriggers )
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_DEBUG_AREATRIGGER_ON );
2011-07-01 03:00:39 +02:00
player -> isDebugAreaTriggers = true ;
2011-10-10 10:33:13 -03:00
}
else
{
2010-11-19 14:04:21 +01:00
handler -> PSendSysMessage ( LANG_DEBUG_AREATRIGGER_OFF );
2011-07-01 03:00:39 +02:00
player -> isDebugAreaTriggers = false ;
2010-11-09 10:15:35 -05:00
}
2023-06-12 12:46:56 +02:00
player -> UpdateObjectVisibility ();
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-09-10 01:05:44 +02:00
static bool HandleDebugSendChannelNotifyCommand ( ChatHandler * handler , ChatNotify type )
2010-11-19 14:04:21 +01:00
{
2018-08-25 22:47:35 +02:00
WorldPackets :: Channel :: ChannelNotify channelNotify ;
2020-09-10 01:05:44 +02:00
channelNotify . Type = type ;
channelNotify . _Channel = "test" ;
2018-08-25 20:13:19 +02:00
handler -> GetSession () -> SendPacket ( channelNotify . Write ());
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-09-10 01:05:44 +02:00
static bool HandleDebugSendChatMsgCommand ( ChatHandler * handler , ChatMsg type )
2010-11-19 14:04:21 +01:00
{
2014-11-16 18:17:08 +02:00
WorldPackets :: Chat :: Chat packet ;
2020-09-10 01:05:44 +02:00
packet . Initialize ( type , LANG_UNIVERSAL , handler -> GetPlayer (), handler -> GetPlayer (), "testtest" , 0 , "chan" );
2014-11-16 18:17:08 +02:00
handler -> GetSession () -> SendPacket ( packet . Write ());
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-09-10 01:05:44 +02:00
static bool HandleDebugSendQuestPartyMsgCommand ( ChatHandler * handler , QuestPushReason msg )
2010-11-19 14:04:21 +01:00
{
2020-09-10 01:05:44 +02:00
handler -> GetSession () -> GetPlayer () -> SendPushToPartyResponse ( handler -> GetPlayer (), msg );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
static bool HandleDebugGetLootRecipientCommand ( ChatHandler * handler )
2010-11-19 14:04:21 +01:00
{
Creature * target = handler -> getSelectedCreature ();
if ( ! target )
return false ;
2010-11-09 10:15:35 -05:00
2022-10-17 23:11:46 +02:00
handler -> PSendSysMessage ( "Loot recipients for creature %s (%s, SpawnID " UI64FMTD ") are:" ,
target -> GetName (). c_str (), target -> GetGUID (). ToString (). c_str (), target -> GetSpawnId ());
for ( ObjectGuid tapperGuid : target -> GetTapList ())
{
Player * tapper = ObjectAccessor :: GetPlayer ( * target , tapperGuid );
handler -> PSendSysMessage ( "* %s" , tapper ? tapper -> GetName (). c_str () : "offline" );
}
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-09-10 01:05:44 +02:00
static bool HandleDebugSendQuestInvalidMsgCommand ( ChatHandler * handler , QuestFailedReason msg )
2010-11-19 14:04:21 +01:00
{
2020-09-10 01:05:44 +02:00
handler -> GetPlayer () -> SendCanTakeQuestResponse ( msg );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
static bool HandleDebugGetItemStateCommand ( ChatHandler * handler , std :: string itemState )
2010-11-19 14:04:21 +01:00
{
ItemUpdateState state = ITEM_UNCHANGED ;
2011-10-10 10:33:13 -03:00
bool listQueue = false ;
bool checkAll = false ;
if ( itemState == "unchanged" )
state = ITEM_UNCHANGED ;
else if ( itemState == "changed" )
state = ITEM_CHANGED ;
else if ( itemState == "new" )
state = ITEM_NEW ;
else if ( itemState == "removed" )
state = ITEM_REMOVED ;
else if ( itemState == "queue" )
listQueue = true ;
else if ( itemState == "check_all" )
checkAll = true ;
else
return false ;
2010-11-19 14:04:21 +01:00
Player * player = handler -> getSelectedPlayer ();
2011-10-10 10:33:13 -03:00
if ( ! player )
2020-09-10 01:05:44 +02:00
player = handler -> GetPlayer ();
2010-11-19 14:04:21 +01:00
2011-10-10 10:33:13 -03:00
if ( ! listQueue && ! checkAll )
2010-11-19 14:04:21 +01:00
{
2011-10-10 10:33:13 -03:00
itemState = "The player has the following " + itemState + " items: " ;
handler -> SendSysMessage ( itemState . c_str ());
2010-11-19 14:04:21 +01:00
for ( uint8 i = PLAYER_SLOT_START ; i < PLAYER_SLOT_END ; ++ i )
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
if ( i >= BUYBACK_SLOT_START && i < BUYBACK_SLOT_END )
continue ;
2010-11-09 10:15:35 -05:00
2011-06-30 14:24:56 +02:00
if ( Item * item = player -> GetItemByPos ( INVENTORY_SLOT_BAG_0 , i ))
2010-11-19 14:04:21 +01:00
{
2011-03-18 15:58:08 +06:00
if ( Bag * bag = item -> ToBag ())
2010-11-09 10:15:35 -05:00
{
2011-03-18 15:58:08 +06:00
for ( uint8 j = 0 ; j < bag -> GetBagSize (); ++ j )
if ( Item * item2 = bag -> GetItemByPos ( j ))
if ( item2 -> GetState () == state )
2014-10-08 17:59:27 +02:00
handler -> PSendSysMessage ( "bag: 255 slot: %d %s owner: %s" , item2 -> GetSlot (), item2 -> GetGUID (). ToString (). c_str (), item2 -> GetOwnerGUID (). ToString (). c_str ());
2010-11-09 10:15:35 -05:00
}
2011-03-18 15:58:08 +06:00
else if ( item -> GetState () == state )
2014-10-08 17:59:27 +02:00
handler -> PSendSysMessage ( "bag: 255 slot: %d %s owner: %s" , item -> GetSlot (), item -> GetGUID (). ToString (). c_str (), item -> GetOwnerGUID (). ToString (). c_str ());
2010-11-09 10:15:35 -05:00
}
}
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
if ( listQueue )
2010-11-19 14:04:21 +01:00
{
2011-10-10 10:33:13 -03:00
std :: vector < Item *>& updateQueue = player -> GetItemUpdateQueue ();
2010-11-19 14:04:21 +01:00
for ( size_t i = 0 ; i < updateQueue . size (); ++ i )
2010-11-09 10:15:35 -05:00
{
2011-06-30 14:24:56 +02:00
Item * item = updateQueue [ i ];
2011-10-10 10:33:13 -03:00
if ( ! item )
continue ;
2010-11-09 10:15:35 -05:00
2011-09-15 14:08:17 +02:00
Bag * container = item -> GetContainer ();
2011-10-10 10:33:13 -03:00
uint8 bagSlot = container ? container -> GetSlot () : uint8 ( INVENTORY_SLOT_BAG_0 );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
std :: string st ;
2011-09-29 12:43:05 +02:00
switch ( item -> GetState ())
2010-11-19 14:04:21 +01:00
{
2011-10-10 10:33:13 -03:00
case ITEM_UNCHANGED :
st = "unchanged" ;
break ;
case ITEM_CHANGED :
st = "changed" ;
break ;
case ITEM_NEW :
st = "new" ;
break ;
case ITEM_REMOVED :
st = "removed" ;
break ;
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
2014-10-22 18:12:51 +02:00
handler -> PSendSysMessage ( "bag: %d slot: %d %s - state: %s" , bagSlot , item -> GetSlot (), item -> GetGUID (). ToString (). c_str (), st . c_str ());
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
if ( updateQueue . empty ())
2011-08-09 07:40:49 -03:00
handler -> PSendSysMessage ( "The player's updatequeue is empty" );
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
if ( checkAll )
2010-11-19 14:04:21 +01:00
{
bool error = false ;
2011-10-10 10:33:13 -03:00
std :: vector < Item *>& updateQueue = player -> GetItemUpdateQueue ();
2010-11-19 14:04:21 +01:00
for ( uint8 i = PLAYER_SLOT_START ; i < PLAYER_SLOT_END ; ++ i )
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
if ( i >= BUYBACK_SLOT_START && i < BUYBACK_SLOT_END )
continue ;
2011-06-30 14:24:56 +02:00
Item * item = player -> GetItemByPos ( INVENTORY_SLOT_BAG_0 , i );
2011-10-10 10:33:13 -03:00
if ( ! item )
continue ;
2010-11-19 14:04:21 +01:00
if ( item -> GetSlot () != i )
2010-11-09 10:15:35 -05:00
{
2014-10-22 18:12:51 +02:00
handler -> PSendSysMessage ( "Item with slot %d and %s has an incorrect slot value: %d" , i , item -> GetGUID (). ToString (). c_str (), item -> GetSlot ());
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( item -> GetOwnerGUID () != player -> GetGUID ())
{
2014-10-08 17:59:27 +02:00
handler -> PSendSysMessage ( "The item with slot %d %s does have non-matching owner guid %s and %s!" , item -> GetSlot (), item -> GetGUID (). ToString (). c_str (), item -> GetOwnerGUID (). ToString (). c_str (), player -> GetGUID (). ToString (). c_str ());
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2011-09-15 14:08:17 +02:00
if ( Bag * container = item -> GetContainer ())
2010-11-19 14:04:21 +01:00
{
2014-10-08 17:59:27 +02:00
handler -> PSendSysMessage ( "The item with slot %d %s has a container (slot: %d, %s) but shouldn't!" , item -> GetSlot (), item -> GetGUID (). ToString (). c_str (), container -> GetSlot (), container -> GetGUID (). ToString (). c_str ());
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-19 14:04:21 +01:00
}
if ( item -> IsInUpdateQueue ())
{
uint16 qp = item -> GetQueuePos ();
if ( qp > updateQueue . size ())
2010-11-09 10:15:35 -05:00
{
2014-10-22 18:12:51 +02:00
handler -> PSendSysMessage ( "The item with slot %d and %s has its queuepos (%d) larger than the update queue size! " , item -> GetSlot (), item -> GetGUID (). ToString (). c_str (), qp );
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-09 10:15:35 -05:00
}
2020-08-14 17:06:03 +02:00
if ( updateQueue [ qp ] == nullptr )
2010-11-09 10:15:35 -05:00
{
2014-10-22 18:12:51 +02:00
handler -> PSendSysMessage ( "The item with slot %d and %s has its queuepos (%d) pointing to NULL in the queue!" , item -> GetSlot (), item -> GetGUID (). ToString (). c_str (), qp );
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
if ( updateQueue [ qp ] != item )
2010-11-09 10:15:35 -05:00
{
2014-10-22 18:12:51 +02:00
handler -> PSendSysMessage ( "The item with slot %d and %s has a queuepos (%d) that points to another item in the queue (bag: %d, slot: %d, %s)" , item -> GetSlot (), item -> GetGUID (). ToString (). c_str (), qp , updateQueue [ qp ] -> GetBagSlot (), updateQueue [ qp ] -> GetSlot (), updateQueue [ qp ] -> GetGUID (). ToString (). c_str ());
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
}
else if ( item -> GetState () != ITEM_UNCHANGED )
{
2014-10-22 18:12:51 +02:00
handler -> PSendSysMessage ( "The item with slot %d and %s is not in queue but should be (state: %d)!" , item -> GetSlot (), item -> GetGUID (). ToString (). c_str (), item -> GetState ());
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2011-03-18 15:58:08 +06:00
if ( Bag * bag = item -> ToBag ())
2010-11-19 14:04:21 +01:00
{
for ( uint8 j = 0 ; j < bag -> GetBagSize (); ++ j )
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
Item * item2 = bag -> GetItemByPos ( j );
2011-10-10 10:33:13 -03:00
if ( ! item2 )
continue ;
2010-11-19 14:04:21 +01:00
if ( item2 -> GetSlot () != j )
2010-11-09 10:15:35 -05:00
{
2014-10-22 18:12:51 +02:00
handler -> PSendSysMessage ( "The item in bag %d and slot %d (%s) has an incorrect slot value: %d" , bag -> GetSlot (), j , item2 -> GetGUID (). ToString (). c_str (), item2 -> GetSlot ());
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
if ( item2 -> GetOwnerGUID () != player -> GetGUID ())
2010-11-09 10:15:35 -05:00
{
2014-10-08 17:59:27 +02:00
handler -> PSendSysMessage ( "The item in bag %d at slot %d and %s, the owner (%s) and the player (%s) don't match!" , bag -> GetSlot (), item2 -> GetSlot (), item2 -> GetGUID (). ToString (). c_str (), item2 -> GetOwnerGUID (). ToString (). c_str (), player -> GetGUID (). ToString (). c_str ());
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-09 10:15:35 -05:00
}
2011-09-15 14:08:17 +02:00
Bag * container = item2 -> GetContainer ();
2010-11-19 14:04:21 +01:00
if ( ! container )
2010-11-09 10:15:35 -05:00
{
2014-10-08 17:59:27 +02:00
handler -> PSendSysMessage ( "The item in bag %d at slot %d %s has no container!" , bag -> GetSlot (), item2 -> GetSlot (), item2 -> GetGUID (). ToString (). c_str ());
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
if ( container != bag )
2010-11-09 10:15:35 -05:00
{
2014-10-08 17:59:27 +02:00
handler -> PSendSysMessage ( "The item in bag %d at slot %d %s has a different container(slot %d %s)!" , bag -> GetSlot (), item2 -> GetSlot (), item2 -> GetGUID (). ToString (). c_str (), container -> GetSlot (), container -> GetGUID (). ToString (). c_str ());
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( item2 -> IsInUpdateQueue ())
{
uint16 qp = item2 -> GetQueuePos ();
if ( qp > updateQueue . size ())
2010-11-09 10:15:35 -05:00
{
2014-10-22 18:12:51 +02:00
handler -> PSendSysMessage ( "The item in bag %d at slot %d having %s has a queuepos (%d) larger than the update queue size! " , bag -> GetSlot (), item2 -> GetSlot (), item2 -> GetGUID (). ToString (). c_str (), qp );
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-09 10:15:35 -05:00
}
2020-08-14 17:06:03 +02:00
if ( updateQueue [ qp ] == nullptr )
2010-11-09 10:15:35 -05:00
{
2014-10-22 18:12:51 +02:00
handler -> PSendSysMessage ( "The item in bag %d at slot %d having %s has a queuepos (%d) that points to NULL in the queue!" , bag -> GetSlot (), item2 -> GetSlot (), item2 -> GetGUID (). ToString (). c_str (), qp );
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
if ( updateQueue [ qp ] != item2 )
2010-11-09 10:15:35 -05:00
{
2014-10-22 18:12:51 +02:00
handler -> PSendSysMessage ( "The item in bag %d at slot %d having %s has a queuepos (%d) that points to another item in the queue (bag: %d, slot: %d, %s)" , bag -> GetSlot (), item2 -> GetSlot (), item2 -> GetGUID (). ToString (). c_str (), qp , updateQueue [ qp ] -> GetBagSlot (), updateQueue [ qp ] -> GetSlot (), updateQueue [ qp ] -> GetGUID (). ToString (). c_str ());
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-09 10:15:35 -05:00
}
}
2010-11-19 14:04:21 +01:00
else if ( item2 -> GetState () != ITEM_UNCHANGED )
{
2014-10-22 18:12:51 +02:00
handler -> PSendSysMessage ( "The item in bag %d at slot %d having %s is not in queue but should be (state: %d)!" , bag -> GetSlot (), item2 -> GetSlot (), item2 -> GetGUID (). ToString (). c_str (), item2 -> GetState ());
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
}
}
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
for ( size_t i = 0 ; i < updateQueue . size (); ++ i )
{
2011-06-30 14:24:56 +02:00
Item * item = updateQueue [ i ];
2011-10-10 10:33:13 -03:00
if ( ! item )
continue ;
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( item -> GetOwnerGUID () != player -> GetGUID ())
{
2014-10-08 17:59:27 +02:00
handler -> PSendSysMessage ( "queue(%zu): For the item %s, the owner (%s) and the player (%s) don't match!" , i , item -> GetGUID (). ToString (). c_str (), item -> GetOwnerGUID (). ToString (). c_str (), player -> GetGUID (). ToString (). c_str ());
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( item -> GetQueuePos () != i )
{
2014-10-08 17:59:27 +02:00
handler -> PSendSysMessage ( "queue(%zu): For the item %s, the queuepos doesn't match it's position in the queue!" , i , item -> GetGUID (). ToString (). c_str ());
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2011-10-10 10:33:13 -03:00
if ( item -> GetState () == ITEM_REMOVED )
continue ;
2011-06-30 14:24:56 +02:00
Item * test = player -> GetItemByPos ( item -> GetBagSlot (), item -> GetSlot ());
2010-11-09 10:15:35 -05:00
2020-08-14 17:06:03 +02:00
if ( test == nullptr )
2010-11-19 14:04:21 +01:00
{
2014-10-08 17:59:27 +02:00
handler -> PSendSysMessage ( "queue(%zu): The bag(%d) and slot(%d) values for %s are incorrect, the player doesn't have any item at that position!" , i , item -> GetBagSlot (), item -> GetSlot (), item -> GetGUID (). ToString (). c_str ());
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( test != item )
{
2014-10-08 17:59:27 +02:00
handler -> PSendSysMessage ( "queue(%zu): The bag(%d) and slot(%d) values for the %s are incorrect, %s is there instead!" , i , item -> GetBagSlot (), item -> GetSlot (), item -> GetGUID (). ToString (). c_str (), test -> GetGUID (). ToString (). c_str ());
2011-10-10 10:33:13 -03:00
error = true ;
continue ;
2010-11-09 10:15:35 -05:00
}
}
2010-11-19 14:04:21 +01:00
if ( ! error )
handler -> SendSysMessage ( "All OK!" );
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
return true ;
}
2020-08-17 22:45:09 +02:00
static bool HandleDebugBattlegroundCommand ( ChatHandler * /*handler*/ )
2010-11-19 14:04:21 +01:00
{
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> ToggleTesting ();
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
static bool HandleDebugArenaCommand ( ChatHandler * /*handler*/ )
2010-11-19 14:04:21 +01:00
{
2010-12-22 21:25:23 +01:00
sBattlegroundMgr -> ToggleArenaTesting ();
2010-11-19 14:04:21 +01:00
return true ;
}
2020-08-17 22:45:09 +02:00
static bool HandleDebugThreatListCommand ( ChatHandler * handler )
2010-11-19 14:04:21 +01:00
{
2018-01-03 20:04:19 +01:00
Unit * target = handler -> getSelectedUnit ();
if ( ! target )
2020-09-10 01:05:44 +02:00
target = handler -> GetPlayer ();
2018-01-09 18:09:24 +01:00
2018-01-03 20:04:19 +01:00
ThreatManager & mgr = target -> GetThreatManager ();
if ( ! target -> IsAlive ())
{
2019-07-21 01:49:58 +02:00
handler -> PSendSysMessage ( "%s (%s) is not alive.%s" , target -> GetName (). c_str (), target -> GetGUID (). ToString (). c_str (), target -> IsEngaged () ? " (It is, however, engaged. Huh?)" : "" );
2018-01-03 20:04:19 +01:00
return true ;
}
2010-11-19 14:04:21 +01:00
2011-10-10 10:33:13 -03:00
uint32 count = 0 ;
2018-01-03 20:04:19 +01:00
auto const & threatenedByMe = target -> GetThreatManager (). GetThreatenedByMeList ();
if ( threatenedByMe . empty ())
handler -> PSendSysMessage ( "%s (%s) does not threaten any units." , target -> GetName (). c_str (), target -> GetGUID (). ToString (). c_str ());
else
2010-11-09 10:15:35 -05:00
{
2018-01-03 20:04:19 +01:00
handler -> PSendSysMessage ( "List of units threatened by %s (%s)" , target -> GetName (). c_str (), target -> GetGUID (). ToString (). c_str ());
for ( auto const & pair : threatenedByMe )
{
Unit * unit = pair . second -> GetOwner ();
2018-02-05 01:33:24 +01:00
handler -> PSendSysMessage ( " %u. %s (%s, SpawnID " UI64FMTD ") - threat %f" , ++ count , unit -> GetName (). c_str (), unit -> GetGUID (). ToString (). c_str (), unit -> GetTypeId () == TYPEID_UNIT ? unit -> ToCreature () -> GetSpawnId () : 0 , pair . second -> GetThreat ());
2018-01-03 20:04:19 +01:00
}
handler -> SendSysMessage ( "End of threatened-by-me list." );
2010-11-09 10:15:35 -05:00
}
2018-01-03 20:04:19 +01:00
2018-02-05 01:33:24 +01:00
if ( mgr . CanHaveThreatList ())
2018-01-03 20:04:19 +01:00
{
2018-02-05 01:33:24 +01:00
if ( ! mgr . IsThreatListEmpty ( true ))
2018-01-03 20:04:19 +01:00
{
2019-06-23 00:32:13 +02:00
if ( target -> IsEngaged ())
2018-02-05 01:33:24 +01:00
handler -> PSendSysMessage ( "Threat list of %s (%s, SpawnID " UI64FMTD "):" , target -> GetName (). c_str (), target -> GetGUID (). ToString (). c_str (), target -> GetTypeId () == TYPEID_UNIT ? target -> ToCreature () -> GetSpawnId () : 0 );
else
handler -> PSendSysMessage ( "%s (%s, SpawnID " UI64FMTD ") is not engaged, but still has a threat list? Well, here it is:" , target -> GetName (). c_str (), target -> GetGUID (). ToString (). c_str (), target -> GetTypeId () == TYPEID_UNIT ? target -> ToCreature () -> GetSpawnId () : 0 );
count = 0 ;
2018-05-04 21:56:48 +02:00
Unit * fixateVictim = mgr . GetFixateTarget ();
2018-02-05 01:33:24 +01:00
for ( ThreatReference const * ref : mgr . GetSortedThreatList ())
2018-01-03 20:04:19 +01:00
{
2018-02-05 01:33:24 +01:00
Unit * unit = ref -> GetVictim ();
char const * onlineStr ;
switch ( ref -> GetOnlineState ())
{
case ThreatReference :: ONLINE_STATE_SUPPRESSED :
onlineStr = " [SUPPRESSED]" ;
break ;
case ThreatReference :: ONLINE_STATE_OFFLINE :
onlineStr = " [OFFLINE]" ;
break ;
default :
onlineStr = "" ;
}
char const * tauntStr ;
2018-05-04 21:56:48 +02:00
if ( unit == fixateVictim )
tauntStr = " [FIXATE]" ;
2018-05-04 14:49:08 +02:00
else
switch ( ref -> GetTauntState ())
{
case ThreatReference :: TAUNT_STATE_TAUNT :
tauntStr = " [TAUNT]" ;
break ;
case ThreatReference :: TAUNT_STATE_DETAUNT :
tauntStr = " [DETAUNT]" ;
break ;
default :
tauntStr = "" ;
}
2018-02-05 01:33:24 +01:00
handler -> PSendSysMessage ( " %u. %s (%s) - threat %f%s%s" , ++ count , unit -> GetName (). c_str (), unit -> GetGUID (). ToString (). c_str (), ref -> GetThreat (), tauntStr , onlineStr );
2018-01-03 20:04:19 +01:00
}
2018-02-05 01:33:24 +01:00
handler -> SendSysMessage ( "End of threat list." );
2018-01-03 20:04:19 +01:00
}
2019-06-23 00:32:13 +02:00
else if ( ! target -> IsEngaged ())
2018-02-05 01:33:24 +01:00
handler -> PSendSysMessage ( "%s (%s, SpawnID " UI64FMTD ") is not currently engaged." , target -> GetName (). c_str (), target -> GetGUID (). ToString (). c_str (), target -> GetTypeId () == TYPEID_UNIT ? target -> ToCreature () -> GetSpawnId () : 0 );
else
handler -> PSendSysMessage ( "%s (%s, SpawnID " UI64FMTD ") seems to be engaged, but does not have a threat list??" , target -> GetName (). c_str (), target -> GetGUID (). ToString (). c_str (), target -> GetTypeId () == TYPEID_UNIT ? target -> ToCreature () -> GetSpawnId () : 0 );
2018-01-03 20:04:19 +01:00
}
2019-06-23 00:32:13 +02:00
else if ( target -> IsEngaged ())
handler -> PSendSysMessage ( "%s (%s) is currently engaged. (This unit cannot have a threat list.)" , target -> GetName (). c_str (), target -> GetGUID (). ToString (). c_str ());
2018-01-03 20:04:19 +01:00
else
2019-06-23 00:32:13 +02:00
handler -> PSendSysMessage ( "%s (%s) is not currently engaged. (This unit cannot have a threat list.)" , target -> GetName (). c_str (), target -> GetGUID (). ToString (). c_str ());
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
static bool HandleDebugThreatInfoCommand ( ChatHandler * handler )
2018-01-09 18:09:24 +01:00
{
Unit * target = handler -> getSelectedUnit ();
if ( ! target )
{
handler -> SendSysMessage ( LANG_SELECT_CHAR_OR_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2022-02-11 14:33:35 +01:00
handler -> PSendSysMessage ( "Threat info for %s (%s):" , target -> GetName (). c_str (), target -> GetGUID (). ToString (). c_str ());
2018-01-09 18:09:24 +01:00
ThreatManager const & mgr = target -> GetThreatManager ();
// _singleSchoolModifiers
{
auto & mods = mgr . _singleSchoolModifiers ;
handler -> SendSysMessage ( " - Single-school threat modifiers:" );
handler -> PSendSysMessage ( " |-- Physical: %.2f%%" , mods [ SPELL_SCHOOL_NORMAL ] * 100.0f );
handler -> PSendSysMessage ( " |-- Holy : %.2f%%" , mods [ SPELL_SCHOOL_HOLY ] * 100.0f );
handler -> PSendSysMessage ( " |-- Fire : %.2f%%" , mods [ SPELL_SCHOOL_FIRE ] * 100.0f );
handler -> PSendSysMessage ( " |-- Nature : %.2f%%" , mods [ SPELL_SCHOOL_NATURE ] * 100.0f );
handler -> PSendSysMessage ( " |-- Frost : %.2f%%" , mods [ SPELL_SCHOOL_FROST ] * 100.0f );
handler -> PSendSysMessage ( " |-- Shadow : %.2f%%" , mods [ SPELL_SCHOOL_SHADOW ] * 100.0f );
handler -> PSendSysMessage ( " |-- Arcane : %.2f%%" , mods [ SPELL_SCHOOL_ARCANE ] * 100.0f );
}
// _multiSchoolModifiers
{
auto & mods = mgr . _multiSchoolModifiers ;
handler -> PSendSysMessage ( "- Multi-school threat modifiers (%zu entries):" , mods . size ());
for ( auto const & pair : mods )
handler -> PSendSysMessage ( " |-- Mask 0x%x: %.2f%%" , uint32 ( pair . first ), pair . second );
}
// _redirectInfo
{
auto const & redirectInfo = mgr . _redirectInfo ;
if ( redirectInfo . empty ())
handler -> SendSysMessage ( " - No redirects being applied" );
else
{
handler -> PSendSysMessage ( " - %02zu redirects being applied:" , redirectInfo . size ());
for ( auto const & pair : redirectInfo )
{
Unit * unit = ObjectAccessor :: GetUnit ( * target , pair . first );
handler -> PSendSysMessage ( " |-- %02u%% to %s" , pair . second , unit ? unit -> GetName (). c_str () : pair . first . ToString (). c_str ());
}
}
}
// _redirectRegistry
{
auto const & redirectRegistry = mgr . _redirectRegistry ;
if ( redirectRegistry . empty ())
handler -> SendSysMessage ( " - No redirects are registered" );
else
{
handler -> PSendSysMessage ( " - %02zu spells may have redirects registered" , redirectRegistry . size ());
for ( auto const & outerPair : redirectRegistry ) // (spellId, (guid, pct))
{
SpellInfo const * const spell = sSpellMgr -> GetSpellInfo ( outerPair . first , DIFFICULTY_NONE );
handler -> PSendSysMessage ( " |-- #%06u %s (%zu entries):" , outerPair . first , spell ? ( * spell -> SpellName )[ sWorld -> GetDefaultDbcLocale ()] : "<unknown>" , outerPair . second . size ());
for ( auto const & innerPair : outerPair . second ) // (guid, pct)
{
Unit * unit = ObjectAccessor :: GetUnit ( * target , innerPair . first );
handler -> PSendSysMessage ( " |-- %02u%% to %s" , innerPair . second , unit ? unit -> GetName (). c_str () : innerPair . first . ToString (). c_str ());
}
}
}
}
return true ;
}
2020-08-17 22:45:09 +02:00
static bool HandleDebugCombatListCommand ( ChatHandler * handler )
2010-11-19 14:04:21 +01:00
{
Unit * target = handler -> getSelectedUnit ();
if ( ! target )
2020-09-10 01:05:44 +02:00
target = handler -> GetPlayer ();
2018-01-03 20:04:19 +01:00
handler -> PSendSysMessage ( "Combat refs: (Combat state: %d | Manager state: %d)" , target -> IsInCombat (), target -> GetCombatManager (). HasCombat ());
for ( auto const & ref : target -> GetCombatManager (). GetPvPCombatRefs ())
2010-11-09 10:15:35 -05:00
{
2018-01-03 20:04:19 +01:00
Unit * unit = ref . second -> GetOther ( target );
handler -> PSendSysMessage ( "[PvP] %s (SpawnID %u)" , unit -> GetName (). c_str (), unit -> GetTypeId () == TYPEID_UNIT ? unit -> ToCreature () -> GetSpawnId () : 0 );
}
for ( auto const & ref : target -> GetCombatManager (). GetPvECombatRefs ())
{
Unit * unit = ref . second -> GetOther ( target );
handler -> PSendSysMessage ( "[PvE] %s (SpawnID %u)" , unit -> GetName (). c_str (), unit -> GetTypeId () == TYPEID_UNIT ? unit -> ToCreature () -> GetSpawnId () : 0 );
2010-11-09 10:15:35 -05:00
}
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
static bool HandleDebugEnterVehicleCommand ( ChatHandler * handler , uint32 entry , Optional < int8 > seatId )
2010-11-19 14:04:21 +01:00
{
Unit * target = handler -> getSelectedUnit ();
if ( ! target || ! target -> IsVehicle ())
return false ;
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
if ( ! seatId )
seatId = - 1 ;
2010-11-19 14:04:21 +01:00
if ( ! entry )
2020-09-10 01:05:44 +02:00
handler -> GetPlayer () -> EnterVehicle ( target , * seatId );
2010-11-19 14:04:21 +01:00
else
{
2020-08-14 17:06:03 +02:00
Creature * passenger = nullptr ;
2020-09-10 01:05:44 +02:00
Trinity :: AllCreaturesOfEntryInRange check ( handler -> GetPlayer (), entry , 20.0f );
Trinity :: CreatureSearcher < Trinity :: AllCreaturesOfEntryInRange > searcher ( handler -> GetPlayer (), passenger , check );
Cell :: VisitAllObjects ( handler -> GetPlayer (), searcher , 30.0f );
2010-11-19 14:04:21 +01:00
if ( ! passenger || passenger == target )
2010-11-09 10:15:35 -05:00
return false ;
2020-08-17 22:45:09 +02:00
passenger -> EnterVehicle ( target , * seatId );
2010-11-19 14:04:21 +01:00
}
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
handler -> PSendSysMessage ( "Unit %u entered vehicle %hhd" , entry , * seatId );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
static bool HandleDebugSpawnVehicleCommand ( ChatHandler * handler , uint32 entry , Optional < uint32 > id )
2010-11-19 14:04:21 +01:00
{
2020-09-10 01:05:44 +02:00
float x , y , z , o = handler -> GetPlayer () -> GetOrientation ();
handler -> GetPlayer () -> GetClosePoint ( x , y , z , handler -> GetPlayer () -> GetCombatReach ());
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
if ( ! id )
2020-09-10 01:05:44 +02:00
return handler -> GetPlayer () -> SummonCreature ( entry , x , y , z , o ) != nullptr ;
2010-11-09 10:15:35 -05:00
2011-09-15 14:08:17 +02:00
CreatureTemplate const * ci = sObjectMgr -> GetCreatureTemplate ( entry );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( ! ci )
return false ;
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
VehicleEntry const * ve = sVehicleStore . LookupEntry ( * id );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( ! ve )
return false ;
2010-11-09 10:15:35 -05:00
2020-09-10 01:05:44 +02:00
Map * map = handler -> GetPlayer () -> GetMap ();
2018-01-27 21:47:37 +01:00
Position pos = { x , y , z , o };
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
Creature * v = Creature :: CreateCreature ( entry , map , pos , * id );
2018-01-27 21:47:37 +01:00
if ( ! v )
2010-11-19 14:04:21 +01:00
return false ;
2010-11-09 10:15:35 -05:00
2020-09-10 01:05:44 +02:00
PhasingHandler :: InheritPhaseShift ( v , handler -> GetPlayer ());
2014-06-01 22:27:29 -05:00
2018-01-27 21:47:37 +01:00
map -> AddToMap ( v );
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
static bool HandleDebugSendLargePacketCommand ( ChatHandler * handler )
2010-11-19 14:04:21 +01:00
{
std :: ostringstream ss ;
while ( ss . str (). size () < 128000 )
2020-09-10 01:05:44 +02:00
ss << "This is a dummy string to push the packet's size beyond 128000 bytes. " ;
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( ss . str (). c_str ());
return true ;
}
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
static bool HandleDebugSendSetPhaseShiftCommand ( ChatHandler * handler , Optional < uint32 > phaseId , Optional < uint32 > visibleMapId , Optional < uint32 > uiMapPhaseId )
2010-11-19 14:04:21 +01:00
{
2018-01-28 11:37:20 +01:00
PhaseShift phaseShift ;
2012-09-26 17:46:00 +02:00
2020-08-17 22:45:09 +02:00
if ( phaseId )
phaseShift . AddPhase ( * phaseId , PhaseFlags :: None , nullptr );
2012-09-26 17:46:00 +02:00
2020-08-17 22:45:09 +02:00
if ( visibleMapId )
phaseShift . AddVisibleMapId ( * visibleMapId , nullptr );
2015-03-16 07:28:49 +01:00
2020-08-17 22:45:09 +02:00
if ( uiMapPhaseId )
phaseShift . AddUiMapPhaseId ( * uiMapPhaseId );
2012-09-26 17:46:00 +02:00
2018-01-28 11:37:20 +01:00
PhasingHandler :: SendToPlayer ( handler -> GetSession () -> GetPlayer (), phaseShift );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
static bool HandleDebugItemExpireCommand ( ChatHandler * handler , ObjectGuid :: LowType guid )
2010-11-19 14:04:21 +01:00
{
2020-09-10 01:05:44 +02:00
Item * i = handler -> GetPlayer () -> GetItemByGuid ( ObjectGuid :: Create < HighGuid :: Item > ( guid ));
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( ! i )
return false ;
2010-11-09 10:15:35 -05:00
2020-09-10 01:05:44 +02:00
handler -> GetPlayer () -> DestroyItem ( i -> GetBagSlot (), i -> GetSlot (), true );
sScriptMgr -> OnItemExpire ( handler -> GetPlayer (), i -> GetTemplate ());
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-08-16 16:26:47 +02:00
// Play emote animation
static bool HandleDebugAnimCommand ( ChatHandler * handler , Emote emote )
2010-11-19 14:04:21 +01:00
{
2016-02-20 15:08:06 +04:00
if ( Unit * unit = handler -> getSelectedUnit ())
2020-08-16 16:26:47 +02:00
unit -> HandleEmoteCommand ( emote );
2020-08-20 00:46:52 +02:00
handler -> PSendSysMessage ( "Playing emote %s" , EnumUtils :: ToConstant ( emote ));
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-08-17 22:45:09 +02:00
static bool HandleDebugLoSCommand ( ChatHandler * handler )
2012-02-03 16:03:52 -05:00
{
if ( Unit * unit = handler -> getSelectedUnit ())
2017-06-10 15:08:35 +02:00
{
2020-09-10 01:05:44 +02:00
Player * player = handler -> GetPlayer ();
2017-06-10 15:08:35 +02:00
handler -> PSendSysMessage ( "Checking LoS %s -> %s:" , player -> GetName (). c_str (), unit -> GetName (). c_str ());
handler -> PSendSysMessage ( " VMAP LoS: %s" , player -> IsWithinLOSInMap ( unit , LINEOFSIGHT_CHECK_VMAP ) ? "clear" : "obstructed" );
handler -> PSendSysMessage ( " GObj LoS: %s" , player -> IsWithinLOSInMap ( unit , LINEOFSIGHT_CHECK_GOBJECT ) ? "clear" : "obstructed" );
handler -> PSendSysMessage ( "%s is %sin line of sight of %s." , unit -> GetName (). c_str (), ( player -> IsWithinLOSInMap ( unit ) ? "" : "not " ), player -> GetName (). c_str ());
return true ;
}
return false ;
2012-02-03 16:03:52 -05:00
}
2010-11-09 10:15:35 -05:00
2020-09-10 01:05:44 +02:00
static bool HandleDebugSetAuraStateCommand ( ChatHandler * handler , Optional < AuraStateType > state , bool apply )
2010-11-19 14:04:21 +01:00
{
Unit * unit = handler -> getSelectedUnit ();
if ( ! unit )
2010-11-09 10:15:35 -05:00
{
2010-11-19 14:04:21 +01:00
handler -> SendSysMessage ( LANG_SELECT_CHAR_OR_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2010-11-09 10:15:35 -05:00
2010-11-19 14:04:21 +01:00
if ( ! state )
{
// reset all states
2020-09-10 01:05:44 +02:00
for ( AuraStateType s : EnumUtils :: Iterate < AuraStateType > ())
unit -> ModifyAuraState ( s , false );
2010-11-09 10:15:35 -05:00
return true ;
}
2020-09-10 01:05:44 +02:00
unit -> ModifyAuraState ( * state , apply );
2010-11-19 14:04:21 +01:00
return true ;
}
2010-11-09 10:15:35 -05:00
2020-09-10 01:05:44 +02:00
static bool HandleDebugMoveflagsCommand ( ChatHandler * handler , Optional < uint32 > moveFlags , Optional < uint32 > moveFlagsExtra )
2012-05-30 08:01:02 +02:00
{
Unit * target = handler -> getSelectedUnit ();
if ( ! target )
2020-09-10 01:05:44 +02:00
target = handler -> GetPlayer ();
2012-05-30 08:01:02 +02:00
2020-09-10 01:05:44 +02:00
if ( ! moveFlags )
2012-05-30 08:01:02 +02:00
{
//! Display case
handler -> PSendSysMessage ( LANG_MOVEFLAGS_GET , target -> GetUnitMovementFlags (), target -> GetExtraUnitMovementFlags ());
}
else
{
2013-08-25 14:38:48 +01:00
/// @fixme: port master's HandleDebugMoveflagsCommand; flags need different handling
2012-05-30 08:01:02 +02:00
2020-09-10 01:05:44 +02:00
if ( moveFlagsExtra )
2012-05-30 08:01:02 +02:00
{
2020-09-10 01:05:44 +02:00
target -> SetExtraUnitMovementFlags ( * moveFlagsExtra );
2012-05-30 08:01:02 +02:00
}
2013-04-09 17:24:39 +02:00
if ( target -> GetTypeId () != TYPEID_PLAYER )
target -> DestroyForNearbyPlayers (); // Force new SMSG_UPDATE_OBJECT:CreateObject
else
{
2015-03-27 22:21:24 +01:00
WorldPackets :: Movement :: MoveUpdate moveUpdate ;
2017-08-16 23:22:41 +02:00
moveUpdate . Status = & target -> m_movementInfo ;
2015-03-27 22:21:24 +01:00
target -> SendMessageToSet ( moveUpdate . Write (), true );
2013-04-09 17:24:39 +02:00
}
2012-05-30 08:01:02 +02:00
handler -> PSendSysMessage ( LANG_MOVEFLAGS_SET , target -> GetUnitMovementFlags (), target -> GetExtraUnitMovementFlags ());
}
return true ;
}
2020-08-17 22:45:09 +02:00
static bool HandleWPGPSCommand ( ChatHandler * handler )
2012-05-30 08:01:02 +02:00
{
2020-09-10 01:05:44 +02:00
Player * player = handler -> GetPlayer ();
2012-05-30 08:01:02 +02:00
2023-01-08 21:16:53 +01:00
TC_LOG_INFO ( "sql.dev" , "(@PATH, XX, {:.3f}, {:.3f}, {:.5f}, {:.5f}, 0, 0, 0, 100, 0)," , player -> GetPositionX (), player -> GetPositionY (), player -> GetPositionZ (), player -> GetOrientation ());
2012-05-30 08:01:02 +02:00
handler -> PSendSysMessage ( "Waypoint SQL written to SQL Developer log" );
return true ;
}
2012-09-26 17:46:00 +02:00
2020-08-17 22:45:09 +02:00
static bool HandleDebugTransportCommand ( ChatHandler * handler , std :: string operation )
2013-10-16 18:37:29 +02:00
{
2022-05-25 22:14:32 +02:00
Transport * transport = dynamic_cast < Transport *> ( handler -> GetPlayer () -> GetTransport ());
2013-10-16 18:37:29 +02:00
if ( ! transport )
return false ;
bool start = false ;
2020-08-17 22:45:09 +02:00
if ( StringEqualI ( operation , "stop" ))
2013-10-16 18:37:29 +02:00
transport -> EnableMovement ( false );
2020-08-17 22:45:09 +02:00
else if ( StringEqualI ( operation , "start" ))
2013-10-16 18:37:29 +02:00
{
transport -> EnableMovement ( true );
start = true ;
}
else
{
2014-04-25 21:19:30 +02:00
Position pos = transport -> GetPosition ();
2013-10-16 18:37:29 +02:00
handler -> PSendSysMessage ( "Transport %s is %s" , transport -> GetName (). c_str (), transport -> GetGoState () == GO_STATE_READY ? "stopped" : "moving" );
2013-12-29 14:59:06 +01:00
handler -> PSendSysMessage ( "Transport position: %s" , pos . ToString (). c_str ());
2013-10-16 18:37:29 +02:00
return true ;
}
handler -> PSendSysMessage ( "Transport %s %s" , transport -> GetName (). c_str (), start ? "started" : "stopped" );
return true ;
}
2013-10-26 17:06:50 +02:00
2020-09-26 16:23:26 +02:00
static bool HandleDebugLoadCellsCommand ( ChatHandler * handler , Optional < uint32 > mapId , Optional < uint32 > tileX , Optional < uint32 > tileY )
2015-08-16 16:39:02 +02:00
{
2020-08-17 22:45:09 +02:00
if ( mapId )
2020-09-26 16:23:26 +02:00
{
2022-07-24 18:56:40 +02:00
sMapMgr -> DoForAllMapsWithMapId ( * mapId , [ & ]( Map * map )
{
HandleDebugLoadCellsCommandHelper ( handler , map , tileX , tileY );
});
return true ;
2020-09-26 16:23:26 +02:00
}
2022-07-24 18:56:40 +02:00
if ( Player * player = handler -> GetPlayer ())
2020-09-26 16:23:26 +02:00
{
// Fallback to player's map if no map has been specified
2022-07-24 18:56:40 +02:00
return HandleDebugLoadCellsCommandHelper ( handler , player -> GetMap (), tileX , tileY );
2020-09-26 16:23:26 +02:00
}
2015-08-16 16:39:02 +02:00
2022-07-24 18:56:40 +02:00
return false ;
}
static bool HandleDebugLoadCellsCommandHelper ( ChatHandler * handler , Map * map , Optional < uint32 > tileX , Optional < uint32 > tileY )
{
2015-08-16 16:39:02 +02:00
if ( ! map )
2020-09-26 16:23:26 +02:00
return false ;
// Load 1 single tile if specified, otherwise load the whole map
if ( tileX && tileY )
{
handler -> PSendSysMessage ( "Loading cell (mapId: %u tile: %u, %u). Current GameObjects " SZFMTD ", Creatures " SZFMTD ,
map -> GetId (), * tileX , * tileY , map -> GetObjectsStore (). Size < GameObject > (), map -> GetObjectsStore (). Size < Creature > ());
// Some unit convertions to go from TileXY to GridXY to WorldXY
float x = (( float ( 64 - 1 - * tileX ) - 0.5f - CENTER_GRID_ID ) * SIZE_OF_GRIDS ) + ( CENTER_GRID_OFFSET * 2 );
float y = (( float ( 64 - 1 - * tileY ) - 0.5f - CENTER_GRID_ID ) * SIZE_OF_GRIDS ) + ( CENTER_GRID_OFFSET * 2 );
map -> LoadGrid ( x , y );
handler -> PSendSysMessage ( "Cell loaded (mapId: %u tile: %u, %u) After load - GameObject " SZFMTD ", Creatures " SZFMTD ,
map -> GetId (), * tileX , * tileY , map -> GetObjectsStore (). Size < GameObject > (), map -> GetObjectsStore (). Size < Creature > ());
}
else
{
handler -> PSendSysMessage ( "Loading all cells (mapId: %u). Current GameObjects " SZFMTD ", Creatures " SZFMTD , map -> GetId (), map -> GetObjectsStore (). Size < GameObject > (), map -> GetObjectsStore (). Size < Creature > ());
map -> LoadAllCells ();
handler -> PSendSysMessage ( "Cells loaded (mapId: %u) After load - GameObject " SZFMTD ", Creatures " SZFMTD , map -> GetId (), map -> GetObjectsStore (). Size < GameObject > (), map -> GetObjectsStore (). Size < Creature > ());
}
2015-08-16 16:39:02 +02:00
return true ;
}
2020-09-10 15:19:17 +02:00
static bool HandleDebugBoundaryCommand ( ChatHandler * handler , Optional < EXACT_SEQUENCE ( "fill" ) > fill , Optional < uint32 > durationArg )
2016-01-13 15:33:17 +01:00
{
2020-09-10 01:05:44 +02:00
Player * player = handler -> GetPlayer ();
2016-01-13 15:33:17 +01:00
if ( ! player )
return false ;
Creature * target = handler -> getSelectedCreature ();
2018-08-23 14:33:28 +02:00
if ( ! target || ! target -> IsAIEnabled ())
2016-01-13 15:33:17 +01:00
return false ;
2020-08-17 22:45:09 +02:00
Seconds duration = durationArg ? Seconds ( * durationArg ) : 0 s ;
if ( duration <= 0 s || duration >= 30 min ) // arbitrary upper limit
2020-07-26 20:44:07 +02:00
duration = 3 min ;
2016-01-13 15:33:17 +01:00
2020-08-17 22:45:09 +02:00
int32 errMsg = target -> AI () -> VisualizeBoundary ( duration , player , fill . has_value ());
2016-01-13 15:33:17 +01:00
if ( errMsg > 0 )
handler -> PSendSysMessage ( errMsg );
return true ;
}
2020-08-17 22:45:09 +02:00
static bool HandleDebugPhaseCommand ( ChatHandler * handler )
2012-09-26 17:46:00 +02:00
{
2015-03-16 07:28:49 +01:00
Unit * target = handler -> getSelectedUnit ();
if ( ! target )
{
handler -> SendSysMessage ( LANG_SELECT_CREATURE );
handler -> SetSentErrorMessage ( true );
return false ;
}
2018-01-06 19:56:11 +01:00
if ( target -> GetDBPhase () > 0 )
handler -> PSendSysMessage ( "Target creature's PhaseId in DB: %d" , target -> GetDBPhase ());
else if ( target -> GetDBPhase () < 0 )
handler -> PSendSysMessage ( "Target creature's PhaseGroup in DB: %d" , abs ( target -> GetDBPhase ()));
2015-03-31 19:49:29 +02:00
2021-12-28 14:24:10 +02:00
PhasingHandler :: PrintToChat ( handler , target );
2012-09-26 17:46:00 +02:00
return true ;
}
2015-07-05 04:03:36 +02:00
2020-08-17 22:45:09 +02:00
static bool HandleDebugRaidResetCommand ( ChatHandler * handler , uint32 mapId , Optional < uint32 > difficulty )
2016-04-05 20:35:59 +02:00
{
2020-08-17 22:45:09 +02:00
MapEntry const * mEntry = sMapStore . LookupEntry ( mapId );
2017-06-03 16:44:54 +02:00
if ( ! mEntry )
{
handler -> PSendSysMessage ( "Invalid map specified." );
2020-08-17 22:45:09 +02:00
return true ;
2017-06-03 16:44:54 +02:00
}
if ( ! mEntry -> IsDungeon ())
{
2020-07-12 15:36:55 +02:00
handler -> PSendSysMessage ( "'%s' is not a dungeon map." , mEntry -> MapName [ handler -> GetSessionDbcLocale ()]);
2017-06-03 16:44:54 +02:00
return true ;
}
2020-08-17 22:45:09 +02:00
if ( difficulty && ! sDifficultyStore . HasRecord ( * difficulty ))
2017-06-03 16:44:54 +02:00
{
2020-08-17 22:45:09 +02:00
handler -> PSendSysMessage ( "Invalid difficulty %d." , * difficulty );
2016-04-05 20:35:59 +02:00
return false ;
2017-06-03 16:44:54 +02:00
}
2020-08-17 22:45:09 +02:00
if ( difficulty && ! sDB2Manager . GetMapDifficultyData ( mEntry -> ID , Difficulty ( * difficulty )))
2017-06-03 16:44:54 +02:00
{
2020-08-17 22:45:09 +02:00
handler -> PSendSysMessage ( "Difficulty %d is not valid for '%s'." , * difficulty , mEntry -> MapName [ handler -> GetSessionDbcLocale ()]);
2017-06-03 16:44:54 +02:00
return true ;
}
2016-04-05 20:35:59 +02:00
return true ;
}
2016-06-14 18:23:45 +02:00
2019-07-16 15:04:14 +02:00
static bool HandleDebugQuestResetCommand ( ChatHandler * handler , std :: string arg )
{
if ( ! Utf8ToUpperOnlyLatin ( arg ))
return false ;
bool daily = false , weekly = false , monthly = false ;
if ( arg == "ALL" )
daily = weekly = monthly = true ;
else if ( arg == "DAILY" )
daily = true ;
else if ( arg == "WEEKLY" )
weekly = true ;
else if ( arg == "MONTHLY" )
monthly = true ;
else
return false ;
if ( daily )
{
2019-08-04 12:22:57 +02:00
sWorld -> DailyReset ();
2022-07-14 22:32:21 +02:00
handler -> PSendSysMessage ( "Daily quests have been reset. Next scheduled reset: %s" , TimeToHumanReadable ( sWorld -> GetPersistentWorldVariable ( World :: NextDailyQuestResetTimeVarId )). c_str ());
2019-07-16 15:04:14 +02:00
}
if ( weekly )
{
2019-08-04 12:22:57 +02:00
sWorld -> ResetWeeklyQuests ();
2022-07-14 22:32:21 +02:00
handler -> PSendSysMessage ( "Weekly quests have been reset. Next scheduled reset: %s" , TimeToHumanReadable ( sWorld -> GetPersistentWorldVariable ( World :: NextWeeklyQuestResetTimeVarId )). c_str ());
2019-07-16 15:04:14 +02:00
}
if ( monthly )
{
2019-08-04 12:22:57 +02:00
sWorld -> ResetMonthlyQuests ();
2022-07-14 22:32:21 +02:00
handler -> PSendSysMessage ( "Monthly quests have been reset. Next scheduled reset: %s" , TimeToHumanReadable ( sWorld -> GetPersistentWorldVariable ( World :: NextMonthlyQuestResetTimeVarId )). c_str ());
2019-07-16 15:04:14 +02:00
}
return true ;
}
2020-09-10 15:19:17 +02:00
static bool HandleDebugNearGraveyard ( ChatHandler * handler , Optional < EXACT_SEQUENCE ( "linked" ) > linked )
2016-06-14 18:23:45 +02:00
{
2020-09-10 01:05:44 +02:00
Player * player = handler -> GetPlayer ();
2016-09-03 19:44:37 +02:00
WorldSafeLocsEntry const * nearestLoc = nullptr ;
2016-06-14 18:23:45 +02:00
2020-08-17 22:45:09 +02:00
if ( linked )
2016-06-14 18:23:45 +02:00
{
2024-03-28 19:29:22 +01:00
if ( Battlefield * bf = sBattlefieldMgr -> GetBattlefieldToZoneId ( player -> GetMap (), player -> GetZoneId ()))
nearestLoc = bf -> GetClosestGraveyard ( player );
2016-06-14 18:23:45 +02:00
else
2024-03-28 19:29:22 +01:00
nearestLoc = sObjectMgr -> GetClosestGraveyard ( * player , player -> GetTeam (), player );
2016-06-14 18:23:45 +02:00
}
else
{
float x = player -> GetPositionX ();
float y = player -> GetPositionY ();
float z = player -> GetPositionZ ();
float distNearest = std :: numeric_limits < float >:: max ();
2019-10-26 23:58:29 +02:00
for ( auto && kvp : sObjectMgr -> GetWorldSafeLocs ())
2016-06-14 18:23:45 +02:00
{
2019-10-26 23:58:29 +02:00
if ( kvp . second . Loc . GetMapId () == player -> GetMapId ())
2016-06-14 18:23:45 +02:00
{
2019-10-26 23:58:29 +02:00
float dist = ( kvp . second . Loc . GetPositionX () - x ) * ( kvp . second . Loc . GetPositionX () - x )
+ ( kvp . second . Loc . GetPositionY () - y ) * ( kvp . second . Loc . GetPositionY () - y )
+ ( kvp . second . Loc . GetPositionZ () - z ) * ( kvp . second . Loc . GetPositionZ () - z );
2016-06-14 18:23:45 +02:00
if ( dist < distNearest )
{
distNearest = dist ;
2019-10-26 23:58:29 +02:00
nearestLoc = & kvp . second ;
2016-06-14 18:23:45 +02:00
}
}
}
}
if ( nearestLoc )
2019-10-26 23:58:29 +02:00
handler -> PSendSysMessage ( LANG_COMMAND_NEARGRAVEYARD , nearestLoc -> ID , nearestLoc -> Loc . GetPositionX (), nearestLoc -> Loc . GetPositionY (), nearestLoc -> Loc . GetPositionZ ());
2016-06-14 18:23:45 +02:00
else
handler -> PSendSysMessage ( LANG_COMMAND_NEARGRAVEYARD_NOTFOUND );
return true ;
}
2017-05-14 11:40:55 +02:00
2020-09-10 15:19:17 +02:00
static bool HandleDebugInstanceSpawns ( ChatHandler * handler , Variant < uint32 , EXACT_SEQUENCE ( "explain" ) > optArg )
2018-01-24 22:52:42 +01:00
{
2020-09-10 01:05:44 +02:00
Player const * const player = handler -> GetPlayer ();
2018-01-24 22:52:42 +01:00
if ( ! player )
return false ;
bool explain = false ;
uint32 groupID = 0 ;
2020-09-10 15:19:17 +02:00
if ( optArg . holds_alternative < uint32 > ())
2020-09-10 01:05:44 +02:00
groupID = optArg . get < uint32 > ();
2020-09-10 15:19:17 +02:00
else
explain = true ;
2018-01-24 22:52:42 +01:00
if ( groupID && ! sObjectMgr -> GetSpawnGroupData ( groupID ))
{
handler -> PSendSysMessage ( "There is no spawn group with ID %u." , groupID );
handler -> SetSentErrorMessage ( true );
return false ;
}
Map const * const map = player -> GetMap ();
char const * const mapName = map -> GetMapName ();
InstanceScript const * const instance = player -> GetInstanceScript ();
if ( ! instance )
{
handler -> PSendSysMessage ( "%s has no instance script." , mapName );
handler -> SetSentErrorMessage ( true );
return false ;
}
if ( ! instance -> _instanceSpawnGroups || instance -> _instanceSpawnGroups -> empty ())
{
handler -> PSendSysMessage ( "%s's instance script does not manage any spawn groups." , mapName );
handler -> SetSentErrorMessage ( true );
return false ;
}
auto const & spawnGroups = * instance -> _instanceSpawnGroups ;
2018-01-25 13:45:11 +01:00
std :: map < uint32 , std :: set < std :: tuple < bool , uint8 , uint8 >>> store ;
2018-01-24 22:52:42 +01:00
for ( InstanceSpawnGroupInfo const & info : spawnGroups )
{
if ( groupID && info . SpawnGroupId != groupID )
continue ;
bool isSpawn ;
if ( info . Flags & InstanceSpawnGroupInfo :: FLAG_BLOCK_SPAWN )
isSpawn = false ;
else if ( info . Flags & InstanceSpawnGroupInfo :: FLAG_ACTIVATE_SPAWN )
isSpawn = true ;
else
continue ;
store [ info . SpawnGroupId ]. emplace ( isSpawn , info . BossStateId , info . BossStates );
}
if ( groupID && store . find ( groupID ) == store . end ())
{
handler -> PSendSysMessage ( "%s's instance script does not manage group '%s'." , mapName , sObjectMgr -> GetSpawnGroupData ( groupID ) -> name . c_str ());
handler -> SetSentErrorMessage ( true );
return false ;
}
if ( ! groupID )
handler -> PSendSysMessage ( "Spawn groups managed by %s (%u):" , mapName , map -> GetId ());
for ( auto const & pair : store )
{
SpawnGroupTemplateData const * groupData = sObjectMgr -> GetSpawnGroupData ( pair . first );
2018-01-25 12:39:19 +01:00
ASSERT ( groupData ); // checked by objectmgr on load
2018-01-24 22:52:42 +01:00
if ( explain )
{
2022-02-11 14:33:35 +01:00
handler -> PSendSysMessage ( " |-- '%s' (%u)" , groupData -> name . c_str (), pair . first );
2018-01-24 22:52:42 +01:00
bool isBlocked = false , isSpawned = false ;
for ( auto const & tuple : pair . second )
{
bool const isSpawn = std :: get < 0 > ( tuple );
uint8 const bossStateId = std :: get < 1 > ( tuple );
EncounterState const actualState = instance -> GetBossState ( bossStateId );
if ( std :: get < 2 > ( tuple ) & ( 1 << actualState ))
{
if ( isSpawn )
{
isSpawned = true ;
if ( isBlocked )
2022-02-11 14:33:35 +01:00
handler -> PSendSysMessage ( " | |-- '%s' would be allowed to spawn by boss state %u being %s, but this is overruled" , groupData -> name . c_str (), bossStateId , InstanceScript :: GetBossStateName ( actualState ));
2018-01-24 22:52:42 +01:00
else
2022-02-11 14:33:35 +01:00
handler -> PSendSysMessage ( " | |-- '%s' is allowed to spawn because boss state %u is %s." , groupData -> name . c_str (), bossStateId , InstanceScript :: GetBossStateName ( bossStateId ));
2018-01-24 22:52:42 +01:00
}
else
{
isBlocked = true ;
2022-02-11 14:33:35 +01:00
handler -> PSendSysMessage ( " | |-- '%s' is blocked from spawning because boss state %u is %s." , groupData -> name . c_str (), bossStateId , InstanceScript :: GetBossStateName ( bossStateId ));
2018-01-24 22:52:42 +01:00
}
}
else
2018-01-25 13:45:11 +01:00
handler -> PSendSysMessage ( " | |-- '%s' could've been %s if boss state %u matched mask 0x%02x; but it is %s -> 0x%02x, which does not match." ,
2022-02-11 14:33:35 +01:00
groupData -> name . c_str (), isSpawn ? "allowed to spawn" : "blocked from spawning" , bossStateId , std :: get < 2 > ( tuple ), InstanceScript :: GetBossStateName ( actualState ), ( 1 << actualState ));
2018-01-24 22:52:42 +01:00
}
if ( isBlocked )
2022-02-11 14:33:35 +01:00
handler -> PSendSysMessage ( " | |=> '%s' is not active due to a blocking rule being matched" , groupData -> name . c_str ());
2018-01-24 22:52:42 +01:00
else if ( isSpawned )
2022-02-11 14:33:35 +01:00
handler -> PSendSysMessage ( " | |=> '%s' is active due to a spawn rule being matched" , groupData -> name . c_str ());
2018-01-24 22:52:42 +01:00
else
2022-02-11 14:33:35 +01:00
handler -> PSendSysMessage ( " | |=> '%s' is not active due to none of its rules being matched" , groupData -> name . c_str ());
2018-01-24 22:52:42 +01:00
}
else
2022-02-11 14:33:35 +01:00
handler -> PSendSysMessage ( " - '%s' (%u) is %sactive" , groupData -> name . c_str (), pair . first , map -> IsSpawnGroupActive ( pair . first ) ? "" : "not " );
2018-01-24 22:52:42 +01:00
}
return true ;
}
2020-09-10 01:05:44 +02:00
static bool HandleDebugConversationCommand ( ChatHandler * handler , uint32 conversationEntry )
2017-05-14 11:40:55 +02:00
{
Player * target = handler -> getSelectedPlayerOrSelf ();
if ( ! target )
{
handler -> SendSysMessage ( LANG_PLAYER_NOT_FOUND );
handler -> SetSentErrorMessage ( true );
return false ;
}
2021-10-09 13:30:47 +02:00
return Conversation :: CreateConversation ( conversationEntry , target , * target , target -> GetGUID ()) != nullptr ;
2017-05-14 11:40:55 +02:00
}
2018-10-23 16:20:45 +02:00
2020-09-10 01:05:44 +02:00
static bool HandleDebugWSExpressionCommand ( ChatHandler * handler , uint32 expressionId )
2018-10-23 16:20:45 +02:00
{
Player * target = handler -> getSelectedPlayerOrSelf ();
if ( ! target )
{
handler -> SendSysMessage ( LANG_PLAYER_NOT_FOUND );
handler -> SetSentErrorMessage ( true );
return false ;
}
WorldStateExpressionEntry const * wsExpressionEntry = sWorldStateExpressionStore . LookupEntry ( expressionId );
if ( ! wsExpressionEntry )
return false ;
2023-06-26 22:53:07 +02:00
if ( ConditionMgr :: IsMeetingWorldStateExpression ( target -> GetMap (), wsExpressionEntry ))
2018-10-23 16:20:45 +02:00
handler -> PSendSysMessage ( "Expression %u meet" , expressionId );
else
handler -> PSendSysMessage ( "Expression %u not meet" , expressionId );
return true ;
2023-05-26 23:51:20 +02:00
}
static bool HandleDebugPlayerConditionCommand ( ChatHandler * handler , uint32 playerConditionId )
{
Player * target = handler -> getSelectedPlayerOrSelf ();
if ( ! target )
{
handler -> SendSysMessage ( LANG_PLAYER_NOT_FOUND );
handler -> SetSentErrorMessage ( true );
return false ;
}
2024-03-27 21:38:08 +01:00
if ( ConditionMgr :: IsPlayerMeetingCondition ( target , playerConditionId ))
2023-05-26 23:51:20 +02:00
handler -> PSendSysMessage ( "PlayerCondition %u met" , playerConditionId );
else
handler -> PSendSysMessage ( "PlayerCondition %u not met" , playerConditionId );
return true ;
}
2018-09-17 11:18:06 +02:00
2020-08-30 02:50:25 +02:00
static bool HandleDebugOutOfBounds ( [[maybe_unused]] ChatHandler * handler )
2019-04-27 18:39:06 +02:00
{
2020-08-17 22:25:11 +02:00
#ifdef ASAN
2019-04-27 18:39:06 +02:00
uint8 stack_array [ 10 ] = {};
int size = 10 ;
2023-08-22 12:56:13 +02:00
handler -> PSendSysMessage ( "Triggered an array out of bounds read at address %p, value %u" , static_cast < void *> ( stack_array + size ), stack_array [ size ]);
2020-08-17 22:25:11 +02:00
#endif
2019-04-27 18:39:06 +02:00
return true ;
}
2020-08-17 22:25:11 +02:00
static bool HandleDebugMemoryLeak ( [[maybe_unused]] ChatHandler * handler )
2019-04-27 18:39:06 +02:00
{
2020-08-17 22:25:11 +02:00
#ifdef ASAN
2019-04-27 18:39:06 +02:00
uint8 * leak = new uint8 ();
2023-08-22 12:56:13 +02:00
handler -> PSendSysMessage ( "Leaked 1 uint8 object at address %p" , static_cast < void *> ( leak ));
2020-08-17 22:25:11 +02:00
#endif
2019-04-27 18:39:06 +02:00
return true ;
}
2020-08-19 00:25:44 +02:00
static bool HandleDebugWardenForce ( ChatHandler * handler , std :: vector < uint16 > checkIds )
{
if ( checkIds . empty ())
return false ;
Warden * const warden = handler -> GetSession () -> GetWarden ();
if ( ! warden )
{
handler -> SendSysMessage ( "Warden system is not enabled" );
return true ;
}
size_t const nQueued = warden -> DEBUG_ForceSpecificChecks ( checkIds );
handler -> PSendSysMessage ( "%zu/%zu checks queued for your Warden, they should be sent over the next few minutes (depending on settings)" , nQueued , checkIds . size ());
return true ;
}
2020-08-17 22:45:09 +02:00
static bool HandleDebugGuidLimitsCommand ( ChatHandler * handler , Optional < uint32 > mapId )
2019-07-13 18:15:39 +02:00
{
if ( mapId )
{
2020-07-15 10:22:29 +02:00
sMapMgr -> DoForAllMapsWithMapId ( mapId . value (),
2019-07-13 18:15:39 +02:00
[ handler ]( Map * map ) -> void
{
HandleDebugGuidLimitsMap ( handler , map );
}
);
}
else
{
sMapMgr -> DoForAllMaps (
[ handler ]( Map * map ) -> void
{
HandleDebugGuidLimitsMap ( handler , map );
}
);
}
handler -> PSendSysMessage ( "Guid Warn Level: %u" , sWorld -> getIntConfig ( CONFIG_RESPAWN_GUIDWARNLEVEL ));
handler -> PSendSysMessage ( "Guid Alert Level: %u" , sWorld -> getIntConfig ( CONFIG_RESPAWN_GUIDALERTLEVEL ));
return true ;
}
static void HandleDebugGuidLimitsMap ( ChatHandler * handler , Map * map )
{
handler -> PSendSysMessage ( "Map Id: %u Name: '%s' Instance Id: %u Highest Guid Creature: " UI64FMTD " GameObject: " UI64FMTD ,
map -> GetId (), map -> GetMapName (), map -> GetInstanceId (), uint64 ( map -> GenerateLowGuid < HighGuid :: Creature > ()), uint64 ( map -> GetMaxLowGuid < HighGuid :: GameObject > ()));
}
2020-08-17 22:45:09 +02:00
static bool HandleDebugObjectCountCommand ( ChatHandler * handler , Optional < uint32 > mapId )
2020-06-14 15:41:01 +02:00
{
if ( mapId )
{
2020-07-15 10:22:29 +02:00
sMapMgr -> DoForAllMapsWithMapId ( mapId . value (),
2020-06-14 15:41:01 +02:00
[ handler ]( Map * map ) -> void
{
HandleDebugObjectCountMap ( handler , map );
}
);
}
else
{
sMapMgr -> DoForAllMaps (
[ handler ]( Map * map ) -> void
{
HandleDebugObjectCountMap ( handler , map );
}
);
}
return true ;
}
2020-08-06 12:58:39 +00:00
class CreatureCountWorker
{
public :
CreatureCountWorker () { }
void Visit ( std :: unordered_map < ObjectGuid , Creature *>& creatureMap )
{
for ( auto const & p : creatureMap )
{
uint32 & count = creatureIds [ p . second -> GetEntry ()];
++ count ;
}
}
template < class T >
void Visit ( std :: unordered_map < ObjectGuid , T *>& ) { }
std :: vector < std :: pair < uint32 , uint32 >> GetTopCreatureCount ( uint32 count )
{
auto comp = []( std :: pair < uint32 , uint32 > const & a , std :: pair < uint32 , uint32 > const & b )
{
return a . second > b . second ;
};
std :: set < std :: pair < uint32 , uint32 > , decltype ( comp ) > set ( creatureIds . begin (), creatureIds . end (), comp );
count = std :: min ( count , uint32 ( set . size ()));
std :: vector < std :: pair < uint32 , uint32 >> result ( count );
std :: copy_n ( set . begin (), count , result . begin ());
return result ;
}
private :
std :: unordered_map < uint32 , uint32 > creatureIds ;
};
2020-06-14 15:41:01 +02:00
static void HandleDebugObjectCountMap ( ChatHandler * handler , Map * map )
{
2021-01-23 15:54:25 +01:00
handler -> PSendSysMessage ( "Map Id: %u Name: '%s' Instance Id: %u Creatures: " UI64FMTD " GameObjects: " UI64FMTD " SetActive Objects: " UI64FMTD ,
2020-06-14 15:41:01 +02:00
map -> GetId (), map -> GetMapName (), map -> GetInstanceId (),
uint64 ( map -> GetObjectsStore (). Size < Creature > ()),
2021-01-23 15:54:25 +01:00
uint64 ( map -> GetObjectsStore (). Size < GameObject > ()),
uint64 ( map -> GetActiveNonPlayersCount ()));
2020-08-06 12:58:39 +00:00
CreatureCountWorker worker ;
TypeContainerVisitor < CreatureCountWorker , MapStoredObjectTypesContainer > visitor ( worker );
visitor . Visit ( map -> GetObjectsStore ());
handler -> PSendSysMessage ( "Top Creatures count:" );
for ( auto && p : worker . GetTopCreatureCount ( 5 ))
handler -> PSendSysMessage ( "Entry: %u Count: %u" , p . first , p . second );
2020-06-14 15:41:01 +02:00
}
2022-01-29 19:44:55 +01:00
static bool HandleDebugBecomePersonalClone ( ChatHandler * handler )
{
Creature * selection = handler -> getSelectedCreature ();
if ( ! selection )
return false ;
Player * player = handler -> GetSession () -> GetPlayer ();
2022-02-08 00:03:02 +01:00
selection -> SummonPersonalClone ( player -> GetPosition (), TEMPSUMMON_MANUAL_DESPAWN , 0 s , 0 , 0 , player );
2022-01-29 19:44:55 +01:00
return true ;
}
2020-08-30 02:50:25 +02:00
static bool HandleDebugDummyCommand ( ChatHandler * handler )
2018-09-17 11:18:06 +02:00
{
handler -> SendSysMessage ( "This command does nothing right now. Edit your local core (cs_debug.cpp) to make it do whatever you need for testing." );
return true ;
}
2010-11-09 10:15:35 -05:00
};
void AddSC_debug_commandscript ()
{
new debug_commandscript ();
}