diff --git a/src/server/scripts/Commands/cs_debug.cpp b/src/server/scripts/Commands/cs_debug.cpp index 32535e86f..94babb7ca 100644 --- a/src/server/scripts/Commands/cs_debug.cpp +++ b/src/server/scripts/Commands/cs_debug.cpp @@ -15,28 +15,33 @@ * with this program. If not, see . */ -/* ScriptData -Name: debug_commandscript -%Complete: 100 -Comment: All debug related commands -Category: commandscripts -EndScriptData */ + /* ScriptData + Name: debug_commandscript + %Complete: 100 + Comment: All debug related commands + Category: commandscripts + EndScriptData */ +#include "ScriptMgr.h" +#include "Bag.h" #include "BattlegroundMgr.h" -#include "Cell.h" #include "CellImpl.h" +#include "Channel.h" #include "Chat.h" #include "GossipDef.h" -#include "GridNotifiers.h" #include "GridNotifiersImpl.h" +#include "InstanceScript.h" #include "Language.h" +#include "Log.h" +#include "MapMgr.h" #include "ObjectMgr.h" -#include "ScriptMgr.h" +#include "PoolMgr.h" +#include "SpellMgr.h" +#include "Transport.h" +#include "Warden.h" +#include "World.h" #include - -#if AC_COMPILER == AC_COMPILER_GNU -#pragma GCC diagnostic ignored "-Wdeprecated-declarations" -#endif +#include using namespace Acore::ChatCommands; @@ -49,90 +54,80 @@ public: { static ChatCommandTable debugPlayCommandTable = { - { "cinematic", SEC_MODERATOR, false, &HandleDebugPlayCinematicCommand, "" }, - { "movie", SEC_MODERATOR, false, &HandleDebugPlayMovieCommand, "" }, - { "sound", SEC_MODERATOR, false, &HandleDebugPlaySoundCommand, "" } + { "cinematic", HandleDebugPlayCinematicCommand, SEC_ADMINISTRATOR, Console::No }, + { "movie", HandleDebugPlayMovieCommand, SEC_ADMINISTRATOR, Console::No }, + { "sound", HandleDebugPlaySoundCommand, SEC_ADMINISTRATOR, Console::No } }; static ChatCommandTable debugSendCommandTable = { - { "buyerror", SEC_ADMINISTRATOR, false, &HandleDebugSendBuyErrorCommand, "" }, - { "channelnotify", SEC_ADMINISTRATOR, false, &HandleDebugSendChannelNotifyCommand, "" }, - { "chatmmessage", SEC_ADMINISTRATOR, false, &HandleDebugSendChatMsgCommand, "" }, - { "equiperror", SEC_ADMINISTRATOR, false, &HandleDebugSendEquipErrorCommand, "" }, - { "largepacket", SEC_ADMINISTRATOR, false, &HandleDebugSendLargePacketCommand, "" }, - { "opcode", SEC_ADMINISTRATOR, false, &HandleDebugSendOpcodeCommand, "" }, - { "qpartymsg", SEC_ADMINISTRATOR, false, &HandleDebugSendQuestPartyMsgCommand, "" }, - { "qinvalidmsg", SEC_ADMINISTRATOR, false, &HandleDebugSendQuestInvalidMsgCommand, "" }, - { "sellerror", SEC_ADMINISTRATOR, false, &HandleDebugSendSellErrorCommand, "" }, - { "setphaseshift", SEC_ADMINISTRATOR, false, &HandleDebugSendSetPhaseShiftCommand, "" }, - { "spellfail", SEC_ADMINISTRATOR, false, &HandleDebugSendSpellFailCommand, "" } + { "buyerror", HandleDebugSendBuyErrorCommand, SEC_ADMINISTRATOR, Console::No }, + { "channelnotify", HandleDebugSendChannelNotifyCommand, SEC_ADMINISTRATOR, Console::No }, + { "chatmmessage", HandleDebugSendChatMsgCommand, SEC_ADMINISTRATOR, Console::No }, + { "equiperror", HandleDebugSendEquipErrorCommand, SEC_ADMINISTRATOR, Console::No }, + { "largepacket", HandleDebugSendLargePacketCommand, SEC_ADMINISTRATOR, Console::No }, + { "opcode", HandleDebugSendOpcodeCommand, SEC_ADMINISTRATOR, Console::No }, + { "qpartymsg", HandleDebugSendQuestPartyMsgCommand, SEC_ADMINISTRATOR, Console::No }, + { "qinvalidmsg", HandleDebugSendQuestInvalidMsgCommand, SEC_ADMINISTRATOR, Console::No }, + { "sellerror", HandleDebugSendSellErrorCommand, SEC_ADMINISTRATOR, Console::No }, + { "setphaseshift", HandleDebugSendSetPhaseShiftCommand, SEC_ADMINISTRATOR, Console::No }, + { "spellfail", HandleDebugSendSpellFailCommand, SEC_ADMINISTRATOR, Console::No } }; static ChatCommandTable debugCommandTable = { - { "setbit", SEC_ADMINISTRATOR, false, &HandleDebugSet32BitCommand, "" }, - { "threat", SEC_ADMINISTRATOR, false, &HandleDebugThreatListCommand, "" }, - { "hostil", SEC_MODERATOR, false, &HandleDebugHostileRefListCommand, "" }, - { "anim", SEC_ADMINISTRATOR, false, &HandleDebugAnimCommand, "" }, - { "arena", SEC_ADMINISTRATOR, false, &HandleDebugArenaCommand, "" }, - { "bg", SEC_ADMINISTRATOR, false, &HandleDebugBattlegroundCommand, "" }, - { "getitemstate", SEC_ADMINISTRATOR, false, &HandleDebugGetItemStateCommand, "" }, - { "lootrecipient", SEC_ADMINISTRATOR, false, &HandleDebugGetLootRecipientCommand, "" }, - { "getvalue", SEC_ADMINISTRATOR, false, &HandleDebugGetValueCommand, "" }, - { "getitemvalue", SEC_ADMINISTRATOR, false, &HandleDebugGetItemValueCommand, "" }, - { "Mod32Value", SEC_ADMINISTRATOR, false, &HandleDebugMod32ValueCommand, "" }, - { "play", SEC_MODERATOR, false, nullptr, "", debugPlayCommandTable }, - { "send", SEC_ADMINISTRATOR, false, nullptr, "", debugSendCommandTable }, - { "setaurastate", SEC_ADMINISTRATOR, false, &HandleDebugSetAuraStateCommand, "" }, - { "setitemvalue", SEC_ADMINISTRATOR, false, &HandleDebugSetItemValueCommand, "" }, - { "setvalue", SEC_ADMINISTRATOR, false, &HandleDebugSetValueCommand, "" }, - { "spawnvehicle", SEC_ADMINISTRATOR, false, &HandleDebugSpawnVehicleCommand, "" }, - { "setvid", SEC_ADMINISTRATOR, false, &HandleDebugSetVehicleIdCommand, "" }, - { "entervehicle", SEC_ADMINISTRATOR, false, &HandleDebugEnterVehicleCommand, "" }, - { "uws", SEC_ADMINISTRATOR, false, &HandleDebugUpdateWorldStateCommand, "" }, - { "update", SEC_ADMINISTRATOR, false, &HandleDebugUpdateCommand, "" }, - { "itemexpire", SEC_ADMINISTRATOR, false, &HandleDebugItemExpireCommand, "" }, - { "areatriggers", SEC_ADMINISTRATOR, false, &HandleDebugAreaTriggersCommand, "" }, - { "lfg", SEC_ADMINISTRATOR, false, &HandleDebugDungeonFinderCommand, "" }, - { "los", SEC_ADMINISTRATOR, false, &HandleDebugLoSCommand, "" }, - { "moveflags", SEC_ADMINISTRATOR, false, &HandleDebugMoveflagsCommand, "" }, - { "unitstate", SEC_ADMINISTRATOR, false, &HandleDebugUnitStateCommand, "" } + { "setbit", HandleDebugSet32BitCommand, SEC_ADMINISTRATOR, Console::No }, + { "threat", HandleDebugThreatListCommand, SEC_ADMINISTRATOR, Console::No }, + { "hostil", HandleDebugHostileRefListCommand, SEC_ADMINISTRATOR, Console::No }, + { "anim", HandleDebugAnimCommand, SEC_ADMINISTRATOR, Console::No }, + { "arena", HandleDebugArenaCommand, SEC_ADMINISTRATOR, Console::No }, + { "bg", HandleDebugBattlegroundCommand, SEC_ADMINISTRATOR, Console::No }, + { "getitemstate", HandleDebugGetItemStateCommand, SEC_ADMINISTRATOR, Console::No }, + { "lootrecipient", HandleDebugGetLootRecipientCommand, SEC_ADMINISTRATOR, Console::No }, + { "getvalue", HandleDebugGetValueCommand, SEC_ADMINISTRATOR, Console::No }, + { "getitemvalue", HandleDebugGetItemValueCommand, SEC_ADMINISTRATOR, Console::No }, + { "Mod32Value", HandleDebugMod32ValueCommand, SEC_ADMINISTRATOR, Console::No }, + { "play", debugPlayCommandTable }, + { "send", debugSendCommandTable }, + { "setaurastate", HandleDebugSetAuraStateCommand, SEC_ADMINISTRATOR, Console::No }, + { "setitemvalue", HandleDebugSetItemValueCommand, SEC_ADMINISTRATOR, Console::No }, + { "setvalue", HandleDebugSetValueCommand, SEC_ADMINISTRATOR, Console::No }, + { "spawnvehicle", HandleDebugSpawnVehicleCommand, SEC_ADMINISTRATOR, Console::No }, + { "setvid", HandleDebugSetVehicleIdCommand, SEC_ADMINISTRATOR, Console::No }, + { "entervehicle", HandleDebugEnterVehicleCommand, SEC_ADMINISTRATOR, Console::No }, + { "uws", HandleDebugUpdateWorldStateCommand, SEC_ADMINISTRATOR, Console::No }, + { "update", HandleDebugUpdateCommand, SEC_ADMINISTRATOR, Console::No }, + { "itemexpire", HandleDebugItemExpireCommand, SEC_ADMINISTRATOR, Console::No }, + { "areatriggers", HandleDebugAreaTriggersCommand, SEC_ADMINISTRATOR, Console::No }, + { "lfg", HandleDebugDungeonFinderCommand, SEC_ADMINISTRATOR, Console::No }, + { "los", HandleDebugLoSCommand, SEC_ADMINISTRATOR, Console::No }, + { "moveflags", HandleDebugMoveflagsCommand, SEC_ADMINISTRATOR, Console::No }, + { "unitstate", HandleDebugUnitStateCommand, SEC_ADMINISTRATOR, Console::No } }; static ChatCommandTable commandTable = { - { "debug", SEC_GAMEMASTER, true, nullptr, "", debugCommandTable }, - { "wpgps", SEC_ADMINISTRATOR, false, &HandleWPGPSCommand, "", } + { "debug", debugCommandTable }, + { "wpgps", HandleWPGPSCommand, SEC_ADMINISTRATOR, Console::No } }; return commandTable; } - static bool HandleDebugPlayCinematicCommand(ChatHandler* handler, char const* args) + // cinematicId - ID from CinematicSequences.dbc + static bool HandleDebugPlayCinematicCommand(ChatHandler* handler, uint32 cinematicId) { - // USAGE: .debug play cinematic #cinematicid - // #cinematicid - ID decimal number from CinemaicSequences.dbc (1st column) - if (!*args) + if (!sCinematicSequencesStore.LookupEntry(cinematicId)) { - handler->SendSysMessage(LANG_BAD_VALUE); - handler->SetSentErrorMessage(true); - return false; - } - - uint32 id = atoi((char*)args); - - if (!sCinematicSequencesStore.LookupEntry(id)) - { - handler->PSendSysMessage(LANG_CINEMATIC_NOT_EXIST, id); + handler->PSendSysMessage(LANG_CINEMATIC_NOT_EXIST, cinematicId); handler->SetSentErrorMessage(true); return false; } // Dump camera locations - if (CinematicSequencesEntry const* cineSeq = sCinematicSequencesStore.LookupEntry(id)) + if (CinematicSequencesEntry const* cineSeq = sCinematicSequencesStore.LookupEntry(cinematicId)) { - std::unordered_map::const_iterator itr = sFlyByCameraStore.find(cineSeq->cinematicCamera); + auto const& itr = sFlyByCameraStore.find(cineSeq->cinematicCamera); if (itr != sFlyByCameraStore.end()) { - handler->PSendSysMessage("Waypoints for sequence %u, camera %u", id, cineSeq->cinematicCamera); - uint32 count = 1 ; + handler->PSendSysMessage("Waypoints for sequence %u, camera %u", cinematicId, cineSeq->cinematicCamera); + uint32 count = 1; for (FlyByCamera cam : itr->second) { handler->PSendSysMessage("%02u - %7ums [%f, %f, %f] Facing %f (%f degrees)", count, cam.timeStamp, cam.locations.x, cam.locations.y, cam.locations.z, cam.locations.w, cam.locations.w * (180 / M_PI)); @@ -142,48 +137,27 @@ public: } } - handler->GetSession()->GetPlayer()->SendCinematicStart(id); + handler->GetSession()->GetPlayer()->SendCinematicStart(cinematicId); return true; } - static bool HandleDebugPlayMovieCommand(ChatHandler* handler, char const* args) + // movieId - ID from Movie.dbc + static bool HandleDebugPlayMovieCommand(ChatHandler* handler, uint32 movieId) { - // USAGE: .debug play movie #movieid - // #movieid - ID decimal number from Movie.dbc (1st column) - if (!*args) + if (!sMovieStore.LookupEntry(movieId)) { - handler->SendSysMessage(LANG_BAD_VALUE); + handler->PSendSysMessage(LANG_MOVIE_NOT_EXIST, movieId); handler->SetSentErrorMessage(true); return false; } - uint32 id = atoi((char*)args); - - if (!sMovieStore.LookupEntry(id)) - { - handler->PSendSysMessage(LANG_MOVIE_NOT_EXIST, id); - handler->SetSentErrorMessage(true); - return false; - } - - handler->GetSession()->GetPlayer()->SendMovieStart(id); + handler->GetPlayer()->SendMovieStart(movieId); return true; } - //Play sound - static bool HandleDebugPlaySoundCommand(ChatHandler* handler, char const* args) + // soundId - ID from SoundEntries.dbc + static bool HandleDebugPlaySoundCommand(ChatHandler* handler, uint32 soundId) { - // USAGE: .debug playsound #soundid - // #soundid - ID decimal number from SoundEntries.dbc (1st column) - if (!*args) - { - handler->SendSysMessage(LANG_BAD_VALUE); - handler->SetSentErrorMessage(true); - return false; - } - - uint32 soundId = atoi((char*)args); - if (!sSoundEntriesStore.LookupEntry(soundId)) { handler->PSendSysMessage(LANG_SOUND_NOT_EXIST, soundId); @@ -191,6 +165,8 @@ public: return false; } + Player* player = handler->GetPlayer(); + Unit* unit = handler->getSelectedUnit(); if (!unit) { @@ -199,89 +175,72 @@ public: return false; } - if (handler->GetSession()->GetPlayer()->GetTarget()) - unit->PlayDistanceSound(soundId, handler->GetSession()->GetPlayer()); + if (player->GetTarget()) + unit->PlayDistanceSound(soundId, player); else - unit->PlayDirectSound(soundId, handler->GetSession()->GetPlayer()); + unit->PlayDirectSound(soundId, player); handler->PSendSysMessage(LANG_YOU_HEAR_SOUND, soundId); return true; } - static bool HandleDebugSendSpellFailCommand(ChatHandler* handler, char const* args) + static bool HandleDebugSendSpellFailCommand(ChatHandler* handler, uint8 result, Optional failArg1, Optional failArg2) { - if (!*args) - return false; - - char* result = strtok((char*)args, " "); - if (!result) - return false; - - uint8 failNum = (uint8)atoi(result); - if (failNum == 0 && *result != '0') - return false; - - char* fail1 = strtok(nullptr, " "); - uint8 failArg1 = fail1 ? (uint8)atoi(fail1) : 0; - - char* fail2 = strtok(nullptr, " "); - uint8 failArg2 = fail2 ? (uint8)atoi(fail2) : 0; - WorldPacket data(SMSG_CAST_FAILED, 5); data << uint8(0); - data << uint32(133); - data << uint8(failNum); - if (fail1 || fail2) - data << uint32(failArg1); - if (fail2) - data << uint32(failArg2); + data << uint32(133); // Spell "Fireball" + data << uint8(result); + + if (failArg1 || failArg2) + { + data << uint32(failArg1.value_or(0)); + } + + if (failArg2) + { + data << uint32(*failArg2); + } handler->GetSession()->SendPacket(&data); - return true; } - static bool HandleDebugSendEquipErrorCommand(ChatHandler* handler, char const* args) + static bool HandleDebugSendEquipErrorCommand(ChatHandler* handler, uint16 error) { - if (!*args) - return false; - - InventoryResult msg = InventoryResult(atoi(args)); - handler->GetSession()->GetPlayer()->SendEquipError(msg, nullptr, nullptr); + handler->GetPlayer()->SendEquipError(InventoryResult(error), nullptr, nullptr); return true; } - static bool HandleDebugSendSellErrorCommand(ChatHandler* handler, char const* args) + static bool HandleDebugSendSellErrorCommand(ChatHandler* handler, uint32 error) { - if (!*args) - return false; - - SellResult msg = SellResult(atoi(args)); - handler->GetSession()->GetPlayer()->SendSellError(msg, 0, ObjectGuid::Empty, 0); + handler->GetPlayer()->SendSellError(SellResult(error), nullptr, ObjectGuid::Empty, 0); return true; } - static bool HandleDebugSendBuyErrorCommand(ChatHandler* handler, char const* args) + static bool HandleDebugSendBuyErrorCommand(ChatHandler* handler, uint16 error) { - if (!*args) - return false; - - BuyResult msg = BuyResult(atoi(args)); - handler->GetSession()->GetPlayer()->SendBuyError(msg, 0, 0, 0); + handler->GetPlayer()->SendBuyError(BuyResult(error), nullptr, 0, 0); return true; } - static bool HandleDebugSendOpcodeCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleDebugSendOpcodeCommand(ChatHandler* handler) { Unit* unit = handler->getSelectedUnit(); Player* player = nullptr; + if (!unit || (unit->GetTypeId() != TYPEID_PLAYER)) + { player = handler->GetSession()->GetPlayer(); + } else + { player = unit->ToPlayer(); + } if (!unit) + { unit = player; + } std::ifstream ifs("opcode.txt"); if (!ifs.is_open()) @@ -326,10 +285,14 @@ public: } // regular data else + { ifs.putback(commentToken[1]); + } } + parsedStream.put(commentToken[0]); } + ifs.close(); uint32 opcode; @@ -446,21 +409,13 @@ public: return true; } - static bool HandleDebugUpdateWorldStateCommand(ChatHandler* handler, char const* args) + static bool HandleDebugUpdateWorldStateCommand(ChatHandler* handler, uint32 variable, uint32 value) { - char* w = strtok((char*)args, " "); - char* s = strtok(nullptr, " "); - - if (!w || !s) - return false; - - uint32 world = (uint32)atoi(w); - uint32 state = (uint32)atoi(s); - handler->GetSession()->GetPlayer()->SendUpdateWorldState(world, state); + handler->GetPlayer()->SendUpdateWorldState(variable, value); return true; } - static bool HandleDebugAreaTriggersCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleDebugAreaTriggersCommand(ChatHandler* handler) { Player* player = handler->GetSession()->GetPlayer(); if (!player->isDebugAreaTriggers) @@ -473,73 +428,55 @@ public: handler->PSendSysMessage(LANG_DEBUG_AREATRIGGER_OFF); player->isDebugAreaTriggers = false; } + return true; } - //Send notification in channel - static bool HandleDebugSendChannelNotifyCommand(ChatHandler* handler, char const* args) + static bool HandleDebugSendChannelNotifyCommand(ChatHandler* handler, uint8 type) { - if (!*args) - return false; - - char const* name = "test"; - uint8 code = atoi(args); - WorldPacket data(SMSG_CHANNEL_NOTIFY, (1 + 10)); - data << code; // notify type - data << name; // channel name + data << type; + data << "test"; data << uint32(0); data << uint32(0); handler->GetSession()->SendPacket(&data); return true; } - //Send notification in chat - static bool HandleDebugSendChatMsgCommand(ChatHandler* handler, char const* args) + static bool HandleDebugSendChatMsgCommand(ChatHandler* handler, uint8 type) { - if (!*args) - return false; - - char const* msg = "testtest"; - uint8 type = atoi(args); WorldPacket data; - ChatHandler::BuildChatPacket(data, ChatMsg(type), LANG_UNIVERSAL, handler->GetSession()->GetPlayer(), handler->GetSession()->GetPlayer(), msg, 0, "chan"); + ChatHandler::BuildChatPacket(data, ChatMsg(type), LANG_UNIVERSAL, handler->GetPlayer(), handler->GetPlayer(), "testtest", 0, "chan"); handler->GetSession()->SendPacket(&data); return true; } - static bool HandleDebugSendQuestPartyMsgCommand(ChatHandler* handler, char const* args) + static bool HandleDebugSendQuestPartyMsgCommand(ChatHandler* handler, uint32 msg) { - uint32 msg = atol((char*)args); - handler->GetSession()->GetPlayer()->SendPushToPartyResponse(handler->GetSession()->GetPlayer(), msg); + handler->GetPlayer()->SendPushToPartyResponse(handler->GetPlayer(), msg); return true; } - static bool HandleDebugGetLootRecipientCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleDebugGetLootRecipientCommand(ChatHandler* handler) { Creature* target = handler->getSelectedCreature(); if (!target) return false; - handler->PSendSysMessage("Loot recipient for creature %s (%s, SpawnId %u) is %s", - target->GetName().c_str(), target->GetGUID().ToString().c_str(), target->GetSpawnId(), target->hasLootRecipient() ? (target->GetLootRecipient() ? target->GetLootRecipient()->GetName().c_str() : "offline") : "no loot recipient"); + handler->PSendSysMessage("Loot recipient for creature %s (GUID %u, SpawnID %u) is %s", + target->GetName().c_str(), target->GetGUID().GetCounter(), target->GetSpawnId(), + target->hasLootRecipient() ? (target->GetLootRecipient() ? target->GetLootRecipient()->GetName().c_str() : "offline") : "no loot recipient"); return true; } - static bool HandleDebugSendQuestInvalidMsgCommand(ChatHandler* handler, char const* args) + static bool HandleDebugSendQuestInvalidMsgCommand(ChatHandler* handler, uint32 msg) { - uint32 msg = atol((char*)args); - handler->GetSession()->GetPlayer()->SendCanTakeQuestResponse(msg); + handler->GetPlayer()->SendCanTakeQuestResponse(msg); return true; } - static bool HandleDebugGetItemStateCommand(ChatHandler* handler, char const* args) + static bool HandleDebugGetItemStateCommand(ChatHandler* handler, std::string itemState) { - if (!*args) - return false; - - std::string itemState = args; - ItemUpdateState state = ITEM_UNCHANGED; bool listQueue = false; bool checkAll = false; @@ -561,7 +498,7 @@ public: Player* player = handler->getSelectedPlayer(); if (!player) - player = handler->GetSession()->GetPlayer(); + player = handler->GetPlayer(); if (!listQueue && !checkAll) { @@ -579,47 +516,43 @@ public: for (uint8 j = 0; j < bag->GetBagSize(); ++j) if (Item* item2 = bag->GetItemByPos(j)) if (item2->GetState() == state) - handler->PSendSysMessage("bag: 255 slot: %d %s, owner: %s", - item2->GetSlot(), item2->GetGUID().ToString().c_str(), item2->GetOwnerGUID().ToString().c_str()); + handler->PSendSysMessage("bag: 255 slot: %d %s owner: %s", item2->GetSlot(), item2->GetGUID().ToString().c_str(), item2->GetOwnerGUID().ToString().c_str()); } else if (item->GetState() == state) - handler->PSendSysMessage("bag: 255 slot: %d %s, owner: %s", - item->GetSlot(), item->GetGUID().ToString().c_str(), item->GetOwnerGUID().ToString().c_str()); + handler->PSendSysMessage("bag: 255 slot: %d %s owner: %s", item->GetSlot(), item->GetGUID().ToString().c_str(), item->GetOwnerGUID().ToString().c_str()); } } } if (listQueue) { - std::vector& updateQueue = player->GetItemUpdateQueue(); - for (size_t i = 0; i < updateQueue.size(); ++i) - { - Item* item = updateQueue[i]; - if (!item) - continue; + auto const& updateQueue = player->GetItemUpdateQueue(); + for (auto const& item : updateQueue) + { Bag* container = item->GetContainer(); uint8 bagSlot = container ? container->GetSlot() : uint8(INVENTORY_SLOT_BAG_0); std::string st; switch (item->GetState()) { - case ITEM_UNCHANGED: - st = "unchanged"; - break; - case ITEM_CHANGED: - st = "changed"; - break; - case ITEM_NEW: - st = "new"; - break; - case ITEM_REMOVED: - st = "removed"; - break; + case ITEM_UNCHANGED: + st = "unchanged"; + break; + case ITEM_CHANGED: + st = "changed"; + break; + case ITEM_NEW: + st = "new"; + break; + case ITEM_REMOVED: + st = "removed"; + break; } - handler->PSendSysMessage("bag: %d slot: %d %s - state: %s", bagSlot, item->GetSlot(), item->GetGUID().ToString().c_str(), st.c_str()); + handler->PSendSysMessage("bag: %d slot: %d guid: %d - state: %s", bagSlot, item->GetSlot(), item->GetGUID().GetCounter(), st.c_str()); } + if (updateQueue.empty()) handler->PSendSysMessage("The player's updatequeue is empty"); } @@ -627,7 +560,7 @@ public: if (checkAll) { bool error = false; - std::vector& updateQueue = player->GetItemUpdateQueue(); + auto const& updateQueue = player->GetItemUpdateQueue(); for (uint8 i = PLAYER_SLOT_START; i < PLAYER_SLOT_END; ++i) { if (i >= BUYBACK_SLOT_START && i < BUYBACK_SLOT_END) @@ -639,23 +572,21 @@ public: if (item->GetSlot() != i) { - handler->PSendSysMessage("Item with slot %d %s has an incorrect slot value: %d", i, item->GetGUID().ToString().c_str(), item->GetSlot()); + handler->PSendSysMessage("Item with slot %d and guid %d has an incorrect slot value: %d", i, item->GetGUID().GetCounter(), item->GetSlot()); error = true; continue; } if (item->GetOwnerGUID() != player->GetGUID()) { - handler->PSendSysMessage("The item with slot %d (%s) does have non-matching owner (%s) and player (%sd) !", - item->GetSlot(), item->GetGUID().ToString().c_str(), item->GetOwnerGUID().ToString().c_str(), player->GetGUID().ToString().c_str()); + 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()); error = true; continue; } if (Bag* container = item->GetContainer()) { - 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()); + 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()); error = true; continue; } @@ -665,32 +596,28 @@ public: uint16 qp = item->GetQueuePos(); if (qp > updateQueue.size()) { - handler->PSendSysMessage("The item with slot %d (%s) has its queuepos (%d) larger than the update queue size! ", - item->GetSlot(), item->GetGUID().ToString().c_str(), qp); + handler->PSendSysMessage("The item with slot %d and guid %d has its queuepos (%d) larger than the update queue size! ", item->GetSlot(), item->GetGUID().GetCounter(), qp); error = true; continue; } if (updateQueue[qp] == nullptr) { - handler->PSendSysMessage("The item with slot %d (%s) has its queuepos (%d) pointing to nullptr in the queue!", - item->GetSlot(), item->GetGUID().ToString().c_str(), qp); + handler->PSendSysMessage("The item with slot %d and guid %d has its queuepos (%d) pointing to NULL in the queue!", item->GetSlot(), item->GetGUID().GetCounter(), qp); error = true; continue; } if (updateQueue[qp] != item) { - handler->PSendSysMessage("The item with slot %d (%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()); + handler->PSendSysMessage("The item with slot %d and guid %d has a queuepos (%d) that points to another item in the queue (bag: %d, slot: %d, guid: %d)", item->GetSlot(), item->GetGUID().GetCounter(), qp, updateQueue[qp]->GetBagSlot(), updateQueue[qp]->GetSlot(), updateQueue[qp]->GetGUID().GetCounter()); error = true; continue; } } else if (item->GetState() != ITEM_UNCHANGED) { - handler->PSendSysMessage("The item with slot %d (%s) is not in queue but should be (state: %d)!", - item->GetSlot(), item->GetGUID().ToString().c_str(), item->GetState()); + handler->PSendSysMessage("The item with slot %d and guid %d is not in queue but should be (state: %d)!", item->GetSlot(), item->GetGUID().GetCounter(), item->GetState()); error = true; continue; } @@ -705,16 +632,14 @@ public: if (item2->GetSlot() != j) { - 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()); + handler->PSendSysMessage("The item in bag %d and slot %d (guid: %d) has an incorrect slot value: %d", bag->GetSlot(), j, item2->GetGUID().GetCounter(), item2->GetSlot()); error = true; continue; } if (item2->GetOwnerGUID() != player->GetGUID()) { - handler->PSendSysMessage("The item in bag %d at slot %d and with item %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()); + 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()); error = true; continue; } @@ -722,16 +647,14 @@ public: Bag* container = item2->GetContainer(); if (!container) { - handler->PSendSysMessage("The item in bag %d at slot %d (%s) has no container!", - bag->GetSlot(), item2->GetSlot(), item2->GetGUID().ToString().c_str()); + handler->PSendSysMessage("The item in bag %d at slot %d %s has no container!", bag->GetSlot(), item2->GetSlot(), item2->GetGUID().ToString().c_str()); error = true; continue; } if (container != bag) { - 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()); + 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()); error = true; continue; } @@ -741,32 +664,28 @@ public: uint16 qp = item2->GetQueuePos(); if (qp > updateQueue.size()) { - handler->PSendSysMessage("The item in bag %d at slot %d (%s) has a queuepos (%d) larger than the update queue size! ", - bag->GetSlot(), item2->GetSlot(), item2->GetGUID().ToString().c_str(), qp); + handler->PSendSysMessage("The item in bag %d at slot %d having guid %d has a queuepos (%d) larger than the update queue size! ", bag->GetSlot(), item2->GetSlot(), item2->GetGUID().GetCounter(), qp); error = true; continue; } if (updateQueue[qp] == nullptr) { - handler->PSendSysMessage("The item in bag %d at slot %d (%s) has a queuepos (%d) that points to nullptr in the queue!", - bag->GetSlot(), item2->GetSlot(), item2->GetGUID().ToString().c_str(), qp); + handler->PSendSysMessage("The item in bag %d at slot %d having guid %d has a queuepos (%d) that points to NULL in the queue!", bag->GetSlot(), item2->GetSlot(), item2->GetGUID().GetCounter(), qp); error = true; continue; } if (updateQueue[qp] != item2) { - handler->PSendSysMessage("The item in bag %d at slot %d (%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()); + handler->PSendSysMessage("The item in bag %d at slot %d having guid %d has a queuepos (%d) that points to another item in the queue (bag: %d, slot: %d, guid: %d)", bag->GetSlot(), item2->GetSlot(), item2->GetGUID().GetCounter(), qp, updateQueue[qp]->GetBagSlot(), updateQueue[qp]->GetSlot(), updateQueue[qp]->GetGUID().GetCounter()); error = true; continue; } } else if (item2->GetState() != ITEM_UNCHANGED) { - handler->PSendSysMessage("The item in bag %d at slot %d (%s) is not in queue but should be (state: %d)!", - bag->GetSlot(), item2->GetSlot(), item2->GetGUID().ToString().c_str(), item2->GetState()); + handler->PSendSysMessage("The item in bag %d at slot %d having guid %d is not in queue but should be (state: %d)!", bag->GetSlot(), item2->GetSlot(), item2->GetGUID().GetCounter(), item2->GetState()); error = true; continue; } @@ -774,23 +693,22 @@ public: } } - for (size_t i = 0; i < updateQueue.size(); ++i) + uint32 index = 0; + + for (auto const& item : updateQueue) { - Item* item = updateQueue[i]; - if (!item) - continue; + index++; if (item->GetOwnerGUID() != player->GetGUID()) { - handler->PSendSysMessage("queue(" SZFMTD "): 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()); + handler->SendSysMessage(Acore::StringFormatFmt("queue({}): For the item {}, the owner ({}) and the player ({}) don't match!", index, item->GetGUID().ToString(), item->GetOwnerGUID().ToString(), player->GetGUID().ToString())); error = true; continue; } - if (item->GetQueuePos() != i) + if (item->GetQueuePos() != index) { - handler->PSendSysMessage("queue(" SZFMTD "): For the item (%s), the queuepos doesn't match it's position in the queue!", i, item->GetGUID().ToString().c_str()); + handler->SendSysMessage(Acore::StringFormatFmt("queue({}): For the item {}, the queuepos doesn't match it's position in the queue!", index, item->GetGUID().ToString())); error = true; continue; } @@ -802,20 +720,19 @@ public: if (test == nullptr) { - handler->PSendSysMessage("queue(" SZFMTD "): The bag(%d) and slot(%d) values for the item (%s) are incorrect, the player doesn't have any item at that position!", - i, item->GetBagSlot(), item->GetSlot(), item->GetGUID().ToString().c_str()); + handler->SendSysMessage(Acore::StringFormatFmt("queue({}): The bag({}) and slot({}) values for {} are incorrect, the player doesn't have any item at that position!", index, item->GetBagSlot(), item->GetSlot(), item->GetGUID().ToString())); error = true; continue; } if (test != item) { - handler->PSendSysMessage("queue(" SZFMTD "): The bag(%d) and slot(%d) values for the item (%s) are incorrect, an item (%s) is there instead!", - i, item->GetBagSlot(), item->GetSlot(), item->GetGUID().ToString().c_str(), test->GetGUID().ToString().c_str()); + handler->SendSysMessage(Acore::StringFormatFmt("queue({}): The bag({}) and slot({}) values for the %s are incorrect, {} is there instead!", index, item->GetBagSlot(), item->GetSlot(), item->GetGUID().ToString(), test->GetGUID().ToString())); error = true; continue; } } + if (!error) handler->SendSysMessage("All OK!"); } @@ -823,34 +740,36 @@ public: return true; } - static bool HandleDebugDungeonFinderCommand(ChatHandler* /*handler*/, char const* /*args*/) + static bool HandleDebugDungeonFinderCommand(ChatHandler* /*handler*/) { sLFGMgr->ToggleTesting(); return true; } - static bool HandleDebugBattlegroundCommand(ChatHandler* /*handler*/, char const* /*args*/) + static bool HandleDebugBattlegroundCommand(ChatHandler* /*handler*/) { sBattlegroundMgr->ToggleTesting(); return true; } - static bool HandleDebugArenaCommand(ChatHandler* /*handler*/, char const* /*args*/) + static bool HandleDebugArenaCommand(ChatHandler* /*handler*/) { sBattlegroundMgr->ToggleArenaTesting(); return true; } - static bool HandleDebugThreatListCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleDebugThreatListCommand(ChatHandler* handler) { Creature* target = handler->getSelectedCreature(); if (!target || target->IsTotem() || target->IsPet()) return false; - ThreatContainer::StorageType const& threatList = target->getThreatMgr().getThreatList(); + auto const& threatList = target->getThreatMgr().getThreatList(); ThreatContainer::StorageType::const_iterator itr; uint32 count = 0; + handler->PSendSysMessage("Threat list of %s (%s)", target->GetName().c_str(), target->GetGUID().ToString().c_str()); + for (itr = threatList.begin(); itr != threatList.end(); ++itr) { Unit* unit = (*itr)->getTarget(); @@ -859,9 +778,11 @@ public: handler->PSendSysMessage(" %u. No Unit - threat %f", ++count, (*itr)->getThreat()); continue; } + handler->PSendSysMessage(" %u. %s (%s) - threat %f", ++count, unit->GetName().c_str(), unit->GetGUID().ToString().c_str(), (*itr)->getThreat()); } - ThreatContainer::StorageType const& threatList2 = target->getThreatMgr().getOfflineThreatList(); + + auto const& threatList2 = target->getThreatMgr().getOfflineThreatList(); for (itr = threatList2.begin(); itr != threatList2.end(); ++itr) { Unit* unit = (*itr)->getTarget(); @@ -870,124 +791,107 @@ public: handler->PSendSysMessage(" %u. [offline] No Unit - threat %f", ++count, (*itr)->getThreat()); continue; } + handler->PSendSysMessage(" %u. [offline] %s (%s) - threat %f", ++count, unit->GetName().c_str(), unit->GetGUID().ToString().c_str(), (*itr)->getThreat()); } + handler->SendSysMessage("End of threat list."); return true; } - static bool HandleDebugHostileRefListCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleDebugHostileRefListCommand(ChatHandler* handler) { Unit* target = handler->getSelectedUnit(); if (!target) target = handler->GetSession()->GetPlayer(); + HostileReference* ref = target->getHostileRefMgr().getFirst(); uint32 count = 0; + handler->PSendSysMessage("Hostil reference list of %s (%s)", target->GetName().c_str(), target->GetGUID().ToString().c_str()); + while (ref) { if (Unit* unit = ref->GetSource()->GetOwner()) + { handler->PSendSysMessage(" %u. %s %s (%s) - threat %f", ++count, (ref->isOnline() ? "" : "[offline]"), unit->GetName().c_str(), unit->GetGUID().ToString().c_str(), ref->getThreat()); + } else + { handler->PSendSysMessage(" %u. No Owner - threat %f", ++count, ref->getThreat()); + } + ref = ref->next(); } + handler->SendSysMessage("End of hostil reference list."); return true; } - static bool HandleDebugSetVehicleIdCommand(ChatHandler* handler, char const* args) + static bool HandleDebugSetVehicleIdCommand(ChatHandler* handler, uint32 id) { Unit* target = handler->getSelectedUnit(); if (!target || target->IsVehicle()) return false; - if (!args) - return false; - - char* i = strtok((char*)args, " "); - if (!i) - return false; - - uint32 id = (uint32)atoi(i); //target->SetVehicleId(id); handler->PSendSysMessage("Vehicle id set to %u", id); return true; } - static bool HandleDebugEnterVehicleCommand(ChatHandler* handler, char const* args) + static bool HandleDebugEnterVehicleCommand(ChatHandler* handler, uint32 entry, Optional seatId) { Unit* target = handler->getSelectedUnit(); if (!target || !target->IsVehicle()) return false; - if (!args) - return false; - - char* i = strtok((char*)args, " "); - if (!i) - return false; - - char* j = strtok(nullptr, " "); - - uint32 entry = (uint32)atoi(i); - int8 seatId = j ? (int8)atoi(j) : -1; + if (!seatId) + seatId = -1; if (!entry) - handler->GetSession()->GetPlayer()->EnterVehicle(target, seatId); + handler->GetPlayer()->EnterVehicle(target, *seatId); else { Creature* passenger = nullptr; - Acore::AllCreaturesOfEntryInRange check(handler->GetSession()->GetPlayer(), entry, 20.0f); - Acore::CreatureSearcher searcher(handler->GetSession()->GetPlayer(), passenger, check); - Cell::VisitAllObjects(handler->GetSession()->GetPlayer(), searcher, 30.0f); + Acore::AllCreaturesOfEntryInRange check(handler->GetPlayer(), entry, 20.0f); + Acore::CreatureSearcher searcher(handler->GetPlayer(), passenger, check); + Cell::VisitAllObjects(handler->GetPlayer(), searcher, 30.0f); + if (!passenger || passenger == target) return false; - passenger->EnterVehicle(target, seatId); + + passenger->EnterVehicle(target, *seatId); } - handler->PSendSysMessage("Unit %u entered vehicle %d", entry, (int32)seatId); + handler->PSendSysMessage("Unit %u entered vehicle %hhd", entry, *seatId); return true; } - static bool HandleDebugSpawnVehicleCommand(ChatHandler* handler, char const* args) + static bool HandleDebugSpawnVehicleCommand(ChatHandler* handler, uint32 entry, Optional id) { - if (!*args) - return false; + float x, y, z, o = handler->GetPlayer()->GetOrientation(); + handler->GetPlayer()->GetClosePoint(x, y, z, handler->GetPlayer()->GetCombatReach()); - char* e = strtok((char*)args, " "); - char* i = strtok(nullptr, " "); - - if (!e) - return false; - - uint32 entry = (uint32)atoi(e); - - float x, y, z, o = handler->GetSession()->GetPlayer()->GetOrientation(); - handler->GetSession()->GetPlayer()->GetClosePoint(x, y, z, handler->GetSession()->GetPlayer()->GetObjectSize()); - - if (!i) - return handler->GetSession()->GetPlayer()->SummonCreature(entry, x, y, z, o); - - uint32 id = (uint32)atoi(i); + if (!id) + return handler->GetPlayer()->SummonCreature(entry, x, y, z, o) != nullptr; CreatureTemplate const* ci = sObjectMgr->GetCreatureTemplate(entry); if (!ci) return false; - VehicleEntry const* ve = sVehicleStore.LookupEntry(id); + VehicleEntry const* ve = sVehicleStore.LookupEntry(*id); if (!ve) return false; - Creature* v = new Creature; + Creature* v = new Creature(); - Map* map = handler->GetSession()->GetPlayer()->GetMap(); + Map* map = handler->GetPlayer()->GetMap(); - if (!v->Create(map->GenerateLowGuid(), map, handler->GetSession()->GetPlayer()->GetPhaseMask(), entry, id, x, y, z, o)) + if (!v->Create(map->GenerateLowGuid(), map, handler->GetSession()->GetPlayer()->GetPhaseMask(), entry, *id, x, y, z, o)) { delete v; return false; @@ -998,41 +902,26 @@ public: return true; } - static bool HandleDebugSendLargePacketCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleDebugSendLargePacketCommand(ChatHandler* handler) { - const char* stuffingString = "This is a dummy string to push the packet's size beyond 128000 bytes. "; std::ostringstream ss; + while (ss.str().size() < 128000) - ss << stuffingString; + ss << "This is a dummy string to push the packet's size beyond 128000 bytes. "; + handler->SendSysMessage(ss.str().c_str()); return true; } - static bool HandleDebugSendSetPhaseShiftCommand(ChatHandler* handler, char const* args) + static bool HandleDebugSendSetPhaseShiftCommand(ChatHandler* handler, uint32 phaseShift) { - if (!*args) - return false; - - uint32 PhaseShift = atoi(args); - handler->GetSession()->SendSetPhaseShift(PhaseShift); + handler->GetSession()->SendSetPhaseShift(phaseShift); return true; } - static bool HandleDebugGetItemValueCommand(ChatHandler* handler, char const* args) + static bool HandleDebugGetItemValueCommand(ChatHandler* handler, ObjectGuid::LowType guid, uint32 index) { - if (!*args) - return false; - - char* e = strtok((char*)args, " "); - char* f = strtok(nullptr, " "); - - if (!e || !f) - return false; - - ObjectGuid::LowType guid = (uint32)atoi(e); - uint32 index = (uint32)atoi(f); - - Item* i = handler->GetSession()->GetPlayer()->GetItemByGuid(ObjectGuid::Create(guid)); + Item* i = handler->GetPlayer()->GetItemByGuid(ObjectGuid(HighGuid::Item, 0, guid)); if (!i) return false; @@ -1047,23 +936,9 @@ public: return true; } - static bool HandleDebugSetItemValueCommand(ChatHandler* handler, char const* args) + static bool HandleDebugSetItemValueCommand(ChatHandler* handler, ObjectGuid::LowType guid, uint32 index, uint32 value) { - if (!*args) - return false; - - char* e = strtok((char*)args, " "); - char* f = strtok(nullptr, " "); - char* g = strtok(nullptr, " "); - - if (!e || !f || !g) - return false; - - ObjectGuid::LowType guid = (uint32)atoi(e); - uint32 index = (uint32)atoi(f); - uint32 value = (uint32)atoi(g); - - Item* i = handler->GetSession()->GetPlayer()->GetItemByGuid(ObjectGuid::Create(guid)); + Item* i = handler->GetPlayer()->GetItemByGuid(ObjectGuid(HighGuid::Item, 0, guid)); if (!i) return false; @@ -1076,40 +951,31 @@ public: return true; } - static bool HandleDebugItemExpireCommand(ChatHandler* handler, char const* args) + static bool HandleDebugItemExpireCommand(ChatHandler* handler, ObjectGuid::LowType guid) { - if (!*args) - return false; - - char* e = strtok((char*)args, " "); - if (!e) - return false; - - ObjectGuid::LowType guid = (uint32)atoi(e); - - Item* i = handler->GetSession()->GetPlayer()->GetItemByGuid(ObjectGuid::Create(guid)); + Item* i = handler->GetPlayer()->GetItemByGuid(ObjectGuid(HighGuid::Item, guid)); if (!i) return false; - handler->GetSession()->GetPlayer()->DestroyItem(i->GetBagSlot(), i->GetSlot(), true); - sScriptMgr->OnItemExpire(handler->GetSession()->GetPlayer(), i->GetTemplate()); + handler->GetPlayer()->DestroyItem(i->GetBagSlot(), i->GetSlot(), true); + sScriptMgr->OnItemExpire(handler->GetPlayer(), i->GetTemplate()); return true; } - //show animation - static bool HandleDebugAnimCommand(ChatHandler* handler, char const* args) + // Play emote animation + static bool HandleDebugAnimCommand(ChatHandler* handler, uint32 emote) { - if (!*args) - return false; + if (Unit* unit = handler->getSelectedUnit()) + unit->HandleEmoteCommand(emote); + + handler->PSendSysMessage("Playing emote %s", emote); - uint32 animId = atoi((char*)args); - handler->GetSession()->GetPlayer()->HandleEmoteCommand(animId); return true; } - static bool HandleDebugLoSCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleDebugLoSCommand(ChatHandler* handler) { if (Unit* unit = handler->getSelectedUnit()) { @@ -1120,18 +986,12 @@ public: 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; } - static bool HandleDebugSetAuraStateCommand(ChatHandler* handler, char const* args) + static bool HandleDebugSetAuraStateCommand(ChatHandler* handler, int32 state) { - if (!*args) - { - handler->SendSysMessage(LANG_BAD_VALUE); - handler->SetSentErrorMessage(true); - return false; - } - Unit* unit = handler->getSelectedUnit(); if (!unit) { @@ -1140,7 +1000,6 @@ public: return false; } - int32 state = atoi((char*)args); if (!state) { // reset all states @@ -1153,18 +1012,8 @@ public: return true; } - static bool HandleDebugSetValueCommand(ChatHandler* handler, char const* args) + static bool HandleDebugSetValueCommand(ChatHandler* handler, uint32 index, Variant value) { - if (!*args) - return false; - - char* x = strtok((char*)args, " "); - char* y = strtok(nullptr, " "); - char* z = strtok(nullptr, " "); - - if (!x || !y) - return false; - WorldObject* target = handler->getSelectedObject(); if (!target) { @@ -1173,46 +1022,28 @@ public: return false; } - ObjectGuid guid = target->GetGUID(); - - uint32 opcode = (uint32)atoi(x); - if (opcode >= target->GetValuesCount()) + if (index >= target->GetValuesCount()) { - handler->PSendSysMessage(LANG_TOO_BIG_INDEX, opcode, guid.GetCounter(), target->GetValuesCount()); + handler->PSendSysMessage(LANG_TOO_BIG_INDEX, index, target->GetGUID().GetCounter(), target->GetValuesCount()); return false; } - bool isInt32 = true; - if (z) - isInt32 = (bool)atoi(z); - - if (isInt32) + if (value.holds_alternative()) { - uint32 value = (uint32)atoi(y); - target->SetUInt32Value(opcode, value); - handler->PSendSysMessage(LANG_SET_UINT_FIELD, guid.GetCounter(), opcode, value); + target->SetUInt32Value(index, value.get()); + handler->PSendSysMessage(LANG_SET_UINT_FIELD, target->GetGUID().GetCounter(), uint32(index), uint32(value)); } - else + else if (value.holds_alternative()) { - float value = (float)atof(y); - target->SetFloatValue(opcode, value); - handler->PSendSysMessage(LANG_SET_FLOAT_FIELD, guid.GetCounter(), opcode, value); + target->SetFloatValue(index, value.get()); + handler->PSendSysMessage(LANG_SET_FLOAT_FIELD, target->GetGUID().GetCounter(), static_cast(index), uint32(value)); } return true; } - static bool HandleDebugGetValueCommand(ChatHandler* handler, char const* args) + static bool HandleDebugGetValueCommand(ChatHandler* handler, uint32 index, bool isInt) { - if (!*args) - return false; - - char* x = strtok((char*)args, " "); - char* z = strtok(nullptr, " "); - - if (!x) - return false; - Unit* target = handler->getSelectedUnit(); if (!target) { @@ -1223,71 +1054,46 @@ public: ObjectGuid guid = target->GetGUID(); - uint32 opcode = (uint32)atoi(x); - if (opcode >= target->GetValuesCount()) + if (index >= target->GetValuesCount()) { - handler->PSendSysMessage(LANG_TOO_BIG_INDEX, opcode, guid.GetCounter(), target->GetValuesCount()); + handler->PSendSysMessage(LANG_TOO_BIG_INDEX, index, guid.GetCounter(), target->GetValuesCount()); return false; } - bool isInt32 = true; - if (z) - isInt32 = (bool)atoi(z); - - if (isInt32) + if (isInt) { - uint32 value = target->GetUInt32Value(opcode); - handler->PSendSysMessage(LANG_GET_UINT_FIELD, guid.GetCounter(), opcode, value); + uint32 value = target->GetUInt32Value(index); + handler->PSendSysMessage(LANG_GET_UINT_FIELD, guid.GetCounter(), index, value); } else { - float value = target->GetFloatValue(opcode); - handler->PSendSysMessage(LANG_GET_FLOAT_FIELD, guid.GetCounter(), opcode, value); + float value = target->GetFloatValue(index); + handler->PSendSysMessage(LANG_GET_FLOAT_FIELD, guid.GetCounter(), index, value); } return true; } - static bool HandleDebugMod32ValueCommand(ChatHandler* handler, char const* args) + static bool HandleDebugMod32ValueCommand(ChatHandler* handler, uint32 index, uint32 value) { - if (!*args) - return false; - - char* x = strtok((char*)args, " "); - char* y = strtok(nullptr, " "); - - if (!x || !y) - return false; - - uint32 opcode = (uint32)atoi(x); - int value = atoi(y); - - if (opcode >= handler->GetSession()->GetPlayer()->GetValuesCount()) + if (index >= handler->GetPlayer()->GetValuesCount()) { - handler->PSendSysMessage(LANG_TOO_BIG_INDEX, opcode, handler->GetSession()->GetPlayer()->GetGUID().GetCounter(), handler->GetSession()->GetPlayer()->GetValuesCount()); + handler->PSendSysMessage(LANG_TOO_BIG_INDEX, index, handler->GetPlayer()->GetGUID().GetCounter(), handler->GetPlayer()->GetValuesCount()); return false; } - int currentValue = (int)handler->GetSession()->GetPlayer()->GetUInt32Value(opcode); + uint32 currentValue = handler->GetPlayer()->GetUInt32Value(index); currentValue += value; - handler->GetSession()->GetPlayer()->SetUInt32Value(opcode, (uint32)currentValue); + handler->GetPlayer()->SetUInt32Value(index, currentValue); - handler->PSendSysMessage(LANG_CHANGE_32BIT_FIELD, opcode, currentValue); + handler->PSendSysMessage(LANG_CHANGE_32BIT_FIELD, index, currentValue); return true; } - static bool HandleDebugUpdateCommand(ChatHandler* handler, char const* args) + static bool HandleDebugUpdateCommand(ChatHandler* handler, uint32 index, Optional value) { - if (!*args) - return false; - - uint32 updateIndex; - uint32 value; - - char* index = strtok((char*)args, " "); - Unit* unit = handler->getSelectedUnit(); if (!unit) { @@ -1299,39 +1105,31 @@ public: if (!index) return true; - updateIndex = atoi(index); - //check updateIndex + // check index if (unit->GetTypeId() == TYPEID_PLAYER) { - if (updateIndex >= PLAYER_END) + if (index >= PLAYER_END) return true; } - else if (updateIndex >= UNIT_END) + else if (index >= UNIT_END) return true; - char* val = strtok(nullptr, " "); - if (!val) + if (!value) { - value = unit->GetUInt32Value(updateIndex); + value = unit->GetUInt32Value(index); - handler->PSendSysMessage(LANG_UPDATE, unit->GetGUID().GetCounter(), updateIndex, value); + handler->PSendSysMessage(LANG_UPDATE, unit->GetGUID().GetCounter(), index, *value); return true; } - value = atoi(val); - - handler->PSendSysMessage(LANG_UPDATE_CHANGE, unit->GetGUID().GetCounter(), updateIndex, value); - - unit->SetUInt32Value(updateIndex, value); + unit->SetUInt32Value(index, *value); + handler->PSendSysMessage(LANG_UPDATE_CHANGE, unit->GetGUID().GetCounter(), index, *value); return true; } - static bool HandleDebugSet32BitCommand(ChatHandler* handler, char const* args) + static bool HandleDebugSet32BitCommand(ChatHandler* handler, uint32 index, uint8 bit) { - if (!*args) - return false; - WorldObject* target = handler->getSelectedObject(); if (!target) { @@ -1340,80 +1138,85 @@ public: return false; } - char* x = strtok((char*)args, " "); - char* y = strtok(nullptr, " "); - - if (!x || !y) + if (bit > 32) // uint32 = 32 bits return false; - uint32 opcode = (uint32)atoi(x); - uint32 val = (uint32)atoi(y); - if (val > 32) //uint32 = 32 bits - return false; + uint32 value = bit ? 1 << (bit - 1) : 0; + target->SetUInt32Value(index, value); - uint32 value = val ? 1 << (val - 1) : 0; - target->SetUInt32Value(opcode, value); - - handler->PSendSysMessage(LANG_SET_32BIT_FIELD, opcode, value); + handler->PSendSysMessage(LANG_SET_32BIT_FIELD, index, value); return true; } - static bool HandleDebugMoveflagsCommand(ChatHandler* handler, char const* args) + static bool HandleDebugMoveflagsCommand(ChatHandler* handler, Optional moveFlags, Optional moveFlagsExtra) { Unit* target = handler->getSelectedUnit(); if (!target) - target = handler->GetSession()->GetPlayer(); + target = handler->GetPlayer(); - if (!*args) + if (!moveFlags) { //! Display case handler->PSendSysMessage(LANG_MOVEFLAGS_GET, target->GetUnitMovementFlags(), target->GetExtraUnitMovementFlags()); } else { - char* mask1 = strtok((char*)args, " "); - if (!mask1) - return false; + static uint32 const FlagsWithHandlers = MOVEMENTFLAG_MASK_HAS_PLAYER_STATUS_OPCODE | + MOVEMENTFLAG_WALKING | MOVEMENTFLAG_SWIMMING | + MOVEMENTFLAG_SPLINE_ENABLED; - char* mask2 = strtok(nullptr, " \n"); + bool unhandledFlag = ((*moveFlags ^ target->GetUnitMovementFlags()) & ~FlagsWithHandlers) != 0; - uint32 moveFlags = (uint32)atoi(mask1); - target->SetUnitMovementFlags(moveFlags); + target->SetWalk((*moveFlags & MOVEMENTFLAG_WALKING) != 0); + target->SetDisableGravity((*moveFlags & MOVEMENTFLAG_DISABLE_GRAVITY) != 0); + target->SetSwim((*moveFlags & MOVEMENTFLAG_SWIMMING) != 0); + target->SetCanFly((*moveFlags & MOVEMENTFLAG_CAN_FLY) != 0); + target->SetWaterWalking((*moveFlags & MOVEMENTFLAG_WATERWALKING) != 0); + target->SetFeatherFall((*moveFlags & MOVEMENTFLAG_FALLING_SLOW) != 0); + target->SetHover((*moveFlags & MOVEMENTFLAG_HOVER) != 0); - if (mask2) + if (*moveFlags & (MOVEMENTFLAG_DISABLE_GRAVITY | MOVEMENTFLAG_CAN_FLY)) + *moveFlags &= ~MOVEMENTFLAG_FALLING; + + if (*moveFlags & MOVEMENTFLAG_ROOT) { - uint32 moveFlagsExtra = uint32(atoi(mask2)); - target->SetExtraUnitMovementFlags(moveFlagsExtra); + target->SetControlled(true, UNIT_STATE_ROOT); + *moveFlags &= ~MOVEMENTFLAG_MASK_MOVING; } - target->SendMovementFlagUpdate(); + if (target->HasUnitMovementFlag(MOVEMENTFLAG_SPLINE_ENABLED) && !(*moveFlags & MOVEMENTFLAG_SPLINE_ENABLED)) + target->StopMoving(); + + if (unhandledFlag) + target->SetUnitMovementFlags(*moveFlags); + + if (moveFlagsExtra) + { + target->SetExtraUnitMovementFlags(*moveFlagsExtra); + } + + if (moveFlagsExtra || unhandledFlag) + target->SendMovementFlagUpdate(); + handler->PSendSysMessage(LANG_MOVEFLAGS_SET, target->GetUnitMovementFlags(), target->GetExtraUnitMovementFlags()); } return true; } - static bool HandleDebugUnitStateCommand(ChatHandler* handler, char const* args) + static bool HandleDebugUnitStateCommand(ChatHandler* handler, uint32 unitState) { Unit* target = handler->getSelectedUnit(); if (!target) target = handler->GetSession()->GetPlayer(); - if (!*args) - { - handler->PSendSysMessage("Unit States: %u, React State: %u", target->GetUnitState(), target->ToCreature() ? target->ToCreature()->GetReactState() : 10); - } - else - { - uint32 unitState = atoi((char*)args); - target->ClearUnitState(target->GetUnitState()); - target->AddUnitState(unitState); - } + target->ClearUnitState(target->GetUnitState()); + target->AddUnitState(unitState); return true; } - static bool HandleWPGPSCommand(ChatHandler* handler, char const* /*args*/) + static bool HandleWPGPSCommand(ChatHandler* handler) { Player* player = handler->GetSession()->GetPlayer();