Core/PacketIO: Rewrite updatefield handling

This commit is contained in:
Shauren
2019-06-08 17:06:57 +02:00
parent 31fda79556
commit 455959c606
368 changed files with 10362 additions and 12544 deletions
-270
View File
@@ -77,7 +77,6 @@ public:
};
static std::vector<ChatCommand> debugCommandTable =
{
{ "setbit", rbac::RBAC_PERM_COMMAND_DEBUG_SETBIT, false, &HandleDebugSet32BitCommand, "" },
{ "threat", rbac::RBAC_PERM_COMMAND_DEBUG_THREAT, false, &HandleDebugThreatListCommand, "" },
{ "hostil", rbac::RBAC_PERM_COMMAND_DEBUG_HOSTIL, false, &HandleDebugHostileRefListCommand, "" },
{ "anim", rbac::RBAC_PERM_COMMAND_DEBUG_ANIM, false, &HandleDebugAnimCommand, "" },
@@ -85,19 +84,13 @@ public:
{ "bg", rbac::RBAC_PERM_COMMAND_DEBUG_BG, true, &HandleDebugBattlegroundCommand, "" },
{ "getitemstate", rbac::RBAC_PERM_COMMAND_DEBUG_GETITEMSTATE, false, &HandleDebugGetItemStateCommand, "" },
{ "lootrecipient", rbac::RBAC_PERM_COMMAND_DEBUG_LOOTRECIPIENT, false, &HandleDebugGetLootRecipientCommand, "" },
{ "getvalue", rbac::RBAC_PERM_COMMAND_DEBUG_GETVALUE, false, &HandleDebugGetValueCommand, "" },
{ "getitemvalue", rbac::RBAC_PERM_COMMAND_DEBUG_GETITEMVALUE, false, &HandleDebugGetItemValueCommand, "" },
{ "Mod32Value", rbac::RBAC_PERM_COMMAND_DEBUG_MOD32VALUE, false, &HandleDebugMod32ValueCommand, "" },
{ "play", rbac::RBAC_PERM_COMMAND_DEBUG_PLAY, false, nullptr, "", debugPlayCommandTable },
{ "send", rbac::RBAC_PERM_COMMAND_DEBUG_SEND, false, nullptr, "", debugSendCommandTable },
{ "setaurastate", rbac::RBAC_PERM_COMMAND_DEBUG_SETAURASTATE, false, &HandleDebugSetAuraStateCommand, "" },
{ "setitemvalue", rbac::RBAC_PERM_COMMAND_DEBUG_SETITEMVALUE, false, &HandleDebugSetItemValueCommand, "" },
{ "setvalue", rbac::RBAC_PERM_COMMAND_DEBUG_SETVALUE, false, &HandleDebugSetValueCommand, "" },
{ "spawnvehicle", rbac::RBAC_PERM_COMMAND_DEBUG_SPAWNVEHICLE, false, &HandleDebugSpawnVehicleCommand, "" },
{ "setvid", rbac::RBAC_PERM_COMMAND_DEBUG_SETVID, false, &HandleDebugSetVehicleIdCommand, "" },
{ "entervehicle", rbac::RBAC_PERM_COMMAND_DEBUG_ENTERVEHICLE, false, &HandleDebugEnterVehicleCommand, "" },
{ "uws", rbac::RBAC_PERM_COMMAND_DEBUG_UWS, false, &HandleDebugUpdateWorldStateCommand, "" },
{ "update", rbac::RBAC_PERM_COMMAND_DEBUG_UPDATE, false, &HandleDebugUpdateCommand, "" },
{ "itemexpire", rbac::RBAC_PERM_COMMAND_DEBUG_ITEMEXPIRE, false, &HandleDebugItemExpireCommand, "" },
{ "areatriggers", rbac::RBAC_PERM_COMMAND_DEBUG_AREATRIGGERS, false, &HandleDebugAreaTriggersCommand, "" },
{ "los", rbac::RBAC_PERM_COMMAND_DEBUG_LOS, false, &HandleDebugLoSCommand, "" },
@@ -991,64 +984,6 @@ public:
return true;
}
static bool HandleDebugGetItemValueCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* e = strtok((char*)args, " ");
char* f = strtok(NULL, " ");
if (!e || !f)
return false;
ObjectGuid::LowType guid = strtoull(e, nullptr, 10);
uint32 index = atoul(f);
Item* i = handler->GetSession()->GetPlayer()->GetItemByGuid(ObjectGuid::Create<HighGuid::Item>(guid));
if (!i)
return false;
if (index >= i->GetValuesCount())
return false;
uint32 value = i->GetUInt32Value(index);
handler->PSendSysMessage("Item " UI64FMTD ": value at %u is %u", guid, index, value);
return true;
}
static bool HandleDebugSetItemValueCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* e = strtok((char*)args, " ");
char* f = strtok(NULL, " ");
char* g = strtok(NULL, " ");
if (!e || !f || !g)
return false;
ObjectGuid::LowType guid = strtoull(e, nullptr, 10);
uint32 index = atoul(f);
uint32 value = atoul(g);
Item* i = handler->GetSession()->GetPlayer()->GetItemByGuid(ObjectGuid::Create<HighGuid::Item>(guid));
if (!i)
return false;
if (index >= i->GetValuesCount())
return false;
i->SetUInt32Value(index, value);
return true;
}
static bool HandleDebugItemExpireCommand(ChatHandler* handler, char const* args)
{
if (!*args)
@@ -1120,211 +1055,6 @@ public:
return true;
}
static bool HandleDebugSetValueCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* x = strtok((char*)args, " ");
char* y = strtok(NULL, " ");
char* z = strtok(NULL, " ");
if (!x || !y)
return false;
WorldObject* target = handler->getSelectedObject();
if (!target)
{
handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
handler->SetSentErrorMessage(true);
return false;
}
ObjectGuid guid = target->GetGUID();
uint32 field = atoul(x);
if (field >= target->GetValuesCount())
{
handler->PSendSysMessage(LANG_TOO_BIG_INDEX, field, guid.ToString().c_str(), target->GetValuesCount());
return false;
}
bool isInt32 = true;
if (z)
isInt32 = atoi(z) != 0;
if (isInt32)
{
uint32 value = atoul(y);
target->SetUInt32Value(field, value);
handler->PSendSysMessage(LANG_SET_UINT_FIELD, guid.ToString().c_str(), field, value);
}
else
{
float value = (float)atof(y);
target->SetFloatValue(field, value);
handler->PSendSysMessage(LANG_SET_FLOAT_FIELD, guid.ToString().c_str(), field, value);
}
return true;
}
static bool HandleDebugGetValueCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* x = strtok((char*)args, " ");
char* z = strtok(NULL, " ");
if (!x)
return false;
Unit* target = handler->getSelectedUnit();
if (!target)
{
handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
handler->SetSentErrorMessage(true);
return false;
}
ObjectGuid guid = target->GetGUID();
uint32 opcode = atoul(x);
if (opcode >= target->GetValuesCount())
{
handler->PSendSysMessage(LANG_TOO_BIG_INDEX, opcode, guid.ToString().c_str(), target->GetValuesCount());
return false;
}
bool isInt32 = true;
if (z)
isInt32 = atoi(z) != 0;
if (isInt32)
{
uint32 value = target->GetUInt32Value(opcode);
handler->PSendSysMessage(LANG_GET_UINT_FIELD, guid.ToString().c_str(), opcode, value);
}
else
{
float value = target->GetFloatValue(opcode);
handler->PSendSysMessage(LANG_GET_FLOAT_FIELD, guid.ToString().c_str(), opcode, value);
}
return true;
}
static bool HandleDebugMod32ValueCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
char* x = strtok((char*)args, " ");
char* y = strtok(NULL, " ");
if (!x || !y)
return false;
uint32 opcode = atoul(x);
int value = atoi(y);
if (opcode >= handler->GetSession()->GetPlayer()->GetValuesCount())
{
handler->PSendSysMessage(LANG_TOO_BIG_INDEX, opcode, handler->GetSession()->GetPlayer()->GetGUID().ToString().c_str(), handler->GetSession()->GetPlayer()->GetValuesCount());
return false;
}
uint32 currentValue = handler->GetSession()->GetPlayer()->GetUInt32Value(opcode);
currentValue += value;
handler->GetSession()->GetPlayer()->SetUInt32Value(opcode, currentValue);
handler->PSendSysMessage(LANG_CHANGE_32BIT_FIELD, opcode, currentValue);
return true;
}
static bool HandleDebugUpdateCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
uint32 updateIndex;
uint32 value;
char* index = strtok((char*)args, " ");
Unit* unit = handler->getSelectedUnit();
if (!unit)
{
handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
handler->SetSentErrorMessage(true);
return false;
}
if (!index)
return true;
updateIndex = atoi(index);
//check updateIndex
if (unit->GetTypeId() == TYPEID_PLAYER)
{
if (updateIndex >= PLAYER_END)
return true;
}
else if (updateIndex >= UNIT_END)
return true;
char* val = strtok(NULL, " ");
if (!val)
{
value = unit->GetUInt32Value(updateIndex);
handler->PSendSysMessage(LANG_UPDATE, unit->GetGUID().ToString().c_str(), updateIndex, value);
return true;
}
value = atoi(val);
handler->PSendSysMessage(LANG_UPDATE_CHANGE, unit->GetGUID().ToString().c_str(), updateIndex, value);
unit->SetUInt32Value(updateIndex, value);
return true;
}
static bool HandleDebugSet32BitCommand(ChatHandler* handler, char const* args)
{
if (!*args)
return false;
WorldObject* target = handler->getSelectedObject();
if (!target)
{
handler->SendSysMessage(LANG_SELECT_CHAR_OR_CREATURE);
handler->SetSentErrorMessage(true);
return false;
}
char* x = strtok((char*)args, " ");
char* y = strtok(NULL, " ");
if (!x || !y)
return false;
uint32 opcode = atoul(x);
uint32 val = atoul(y);
if (val > 32) //uint32 = 32 bits
return false;
uint32 value = val ? 1 << (val - 1) : 0;
target->SetUInt32Value(opcode, value);
handler->PSendSysMessage(LANG_SET_32BIT_FIELD, opcode, value);
return true;
}
static bool HandleDebugMoveflagsCommand(ChatHandler* handler, char const* args)
{
Unit* target = handler->getSelectedUnit();