Ayo,
recently I've come across an issue with a customer who had item proto entries all over the place and when the database tried to sort that mess, it messed it up even more, eventually, it messed up this very Monday for me as I spent hours debugging this.
Long story short: It first inserts key-value to map m_map_itemTableByVnum where the key was an integer (item vnum) and the value was a pointer that pointed to an item table object at position X in m_vec_itemTable but at the end, it sorted this very vector while values in map still pointed to the same positions in the vector. Guessed what happened? An item with vnum 19709 had an item table of the item with vnum 20009 because you donkey were too lazy to put new proto entries in the correct order.
Go over to server source, database/ClientManagerBoot.cpp, at the end of the following function:
bool CClientManager::InitializeItemTable()
{
[...]
m_map_itemTableByVnum.clear();
auto it = m_vec_itemTable.begin();
while (it != m_vec_itemTable.end())
{
TItemTable * item_table = &(*(it++));
sys_log(1, "ITEM: #%-5lu %-24s %-24s VAL: %ld %ld %ld %ld %ld %ld WEAR %lu ANTI %lu IMMUNE %lu REFINE %lu REFINE_SET %u MAGIC_PCT %u",
item_table->dwVnum,
item_table->szName,
item_table->szLocaleName,
item_table->alValues[0],
item_table->alValues[1],
item_table->alValues[2],
item_table->alValues[3],
item_table->alValues[4],
item_table->alValues[5],
item_table->dwWearFlags,
item_table->dwAntiFlags,
item_table->dwImmuneFlag,
item_table->dwRefinedVnum,
item_table->wRefineSet,
item_table->bAlterToMagicItemPct);
m_map_itemTableByVnum.insert(std::map<DWORD, TItemTable *>::value_type(item_table->dwVnum, item_table));
}
sort(m_vec_itemTable.begin(), m_vec_itemTable.end(), FCompareVnum());
return true;
Now we'll do some dark magic, we'll move the sort function at the beginning of previously shown code, like so:
bool CClientManager::InitializeItemTable()
{
[...]
m_map_itemTableByVnum.clear();
// -------------------------------------------------------------> Wohoo I am here now!
sort(m_vec_itemTable.begin(), m_vec_itemTable.end(), FCompareVnum());
auto it = m_vec_itemTable.begin();
while (it != m_vec_itemTable.end())
{
TItemTable * item_table = &(*(it++));
sys_log(1, "ITEM: #%-5lu %-24s %-24s VAL: %ld %ld %ld %ld %ld %ld WEAR %lu ANTI %lu IMMUNE %lu REFINE %lu REFINE_SET %u MAGIC_PCT %u",
item_table->dwVnum,
item_table->szName,
item_table->szLocaleName,
item_table->alValues[0],
item_table->alValues[1],
item_table->alValues[2],
item_table->alValues[3],
item_table->alValues[4],
item_table->alValues[5],
item_table->dwWearFlags,
item_table->dwAntiFlags,
item_table->dwImmuneFlag,
item_table->dwRefinedVnum,
item_table->wRefineSet,
item_table->bAlterToMagicItemPct);
m_map_itemTableByVnum.insert(std::map<DWORD, TItemTable *>::value_type(item_table->dwVnum, item_table));
}
return true;