From f46245fe5d7374ba2562d23b308c7ce930b27e76 Mon Sep 17 00:00:00 2001 From: tomrus88 Date: Sat, 13 Dec 2008 01:12:01 +0300 Subject: [PATCH] Character re-customization fix --- src/game/Level3.cpp | 28 +++++++++++++++------------- src/game/Player.cpp | 46 ++++++++++++++++++++++++++-------------------- src/game/World.cpp | 22 +++++++++++----------- 3 files changed, 52 insertions(+), 44 deletions(-) diff --git a/src/game/Level3.cpp b/src/game/Level3.cpp index 3c3393876..9931bb39a 100644 --- a/src/game/Level3.cpp +++ b/src/game/Level3.cpp @@ -6504,30 +6504,27 @@ bool ChatHandler::HandleModifyGenderCommand(const char *args) return false; } + PlayerInfo const* info = objmgr.GetPlayerInfo(player->getRace(), player->getClass()); + if(!info) + return false; + char const* gender_str = (char*)args; int gender_len = strlen(gender_str); - uint32 displayId = player->GetNativeDisplayId(); - char const* gender_full = NULL; - uint32 new_displayId = displayId; Gender gender; - if(!strncmp(gender_str,"male",gender_len)) // MALE + if(!strncmp(gender_str, "male", gender_len)) // MALE { if(player->getGender() == GENDER_MALE) return true; - gender_full = "male"; - new_displayId = player->getRace() == RACE_BLOODELF ? displayId+1 : displayId-1; gender = GENDER_MALE; } - else if (!strncmp(gender_str,"female",gender_len)) // FEMALE + else if (!strncmp(gender_str, "female", gender_len)) // FEMALE { if(player->getGender() == GENDER_FEMALE) return true; - gender_full = "female"; - new_displayId = player->getRace() == RACE_BLOODELF ? displayId-1 : displayId+1; gender = GENDER_FEMALE; } else @@ -6539,13 +6536,18 @@ bool ChatHandler::HandleModifyGenderCommand(const char *args) // Set gender player->SetByteValue(UNIT_FIELD_BYTES_0, 2, gender); + player->SetByteValue(PLAYER_BYTES_3, 0, gender); // Change display ID - player->SetDisplayId(new_displayId); - player->SetNativeDisplayId(new_displayId); + player->SetDisplayId(gender ? info->displayId_f : info->displayId_m); + player->SetNativeDisplayId(gender ? info->displayId_f : info->displayId_m); + + char const* gender_full = gender ? "female" : "male"; + + PSendSysMessage(LANG_YOU_CHANGE_GENDER, player->GetName(), gender_full); - PSendSysMessage(LANG_YOU_CHANGE_GENDER, player->GetName(),gender_full); if (needReportToTarget(player)) - ChatHandler(player).PSendSysMessage(LANG_YOUR_GENDER_CHANGED, gender_full,GetName()); + ChatHandler(player).PSendSysMessage(LANG_YOUR_GENDER_CHANGED, gender_full, GetName()); + return true; } diff --git a/src/game/Player.cpp b/src/game/Player.cpp index 02f3d062d..e78496246 100644 --- a/src/game/Player.cpp +++ b/src/game/Player.cpp @@ -15772,31 +15772,37 @@ void Player::SetFloatValueInDB(uint16 index, float value, uint64 guid) void Player::Customize(uint64 guid, uint8 gender, uint8 skin, uint8 face, uint8 hairStyle, uint8 hairColor, uint8 facialHair) { Tokens tokens; - if(!LoadValuesArrayFromDB(tokens,guid)) + if(!LoadValuesArrayFromDB(tokens, guid)) return; - uint32 player_bytes = atol(tokens[PLAYER_BYTES].c_str()); - ((uint8*)player_bytes)[0] = skin; - ((uint8*)player_bytes)[1] = face; - ((uint8*)player_bytes)[2] = hairStyle; - ((uint8*)player_bytes)[3] = hairColor; - char buf[11]; - snprintf(buf,11,"%u",player_bytes); - tokens[PLAYER_BYTES] = buf; + uint32 unit_bytes0 = GetUInt32ValueFromArray(tokens, UNIT_FIELD_BYTES_0); + uint8 race = unit_bytes0 & 0xFF; + uint8 class_ = (unit_bytes0 >> 8) & 0xFF; + + PlayerInfo const* info = objmgr.GetPlayerInfo(race, class_); + if(!info) + return; - uint32 player_bytes2 = atol(tokens[PLAYER_BYTES_2].c_str()); - ((uint8*)player_bytes2)[0] = facialHair; - char buf2[11]; - snprintf(buf2,11,"%u",player_bytes2); - tokens[PLAYER_BYTES_2] = buf; + unit_bytes0 &= ~(0xFF << 16); + unit_bytes0 |= (gender << 16); + SetUInt32ValueInArray(tokens, UNIT_FIELD_BYTES_0, unit_bytes0); - uint32 player_bytes3 = atol(tokens[PLAYER_BYTES_3].c_str()); - ((uint8*)player_bytes3)[0] = gender; - char buf3[11]; - snprintf(buf3,11,"%u",player_bytes3); - tokens[PLAYER_BYTES_3] = buf; + SetUInt32ValueInArray(tokens, UNIT_FIELD_DISPLAYID, gender ? info->displayId_f : info->displayId_m); + SetUInt32ValueInArray(tokens, UNIT_FIELD_NATIVEDISPLAYID, gender ? info->displayId_f : info->displayId_m); - SaveValuesArrayInDB(tokens,guid); + SetUInt32ValueInArray(tokens, PLAYER_BYTES, (skin | (face << 8) | (hairStyle << 16) | (hairColor << 24))); + + uint32 player_bytes2 = GetUInt32ValueFromArray(tokens, PLAYER_BYTES_2); + player_bytes2 &= ~0xFF; + player_bytes2 |= facialHair; + SetUInt32ValueInArray(tokens, PLAYER_BYTES_2, player_bytes2); + + uint32 player_bytes3 = GetUInt32ValueFromArray(tokens, PLAYER_BYTES_3); + player_bytes3 &= ~0xFF; + player_bytes3 |= gender; + SetUInt32ValueInArray(tokens, PLAYER_BYTES_3, player_bytes3); + + SaveValuesArrayInDB(tokens, guid); } void Player::SendAttackSwingNotStanding() diff --git a/src/game/World.cpp b/src/game/World.cpp index 9794ba523..149833a12 100644 --- a/src/game/World.cpp +++ b/src/game/World.cpp @@ -226,7 +226,7 @@ World::AddSession_ (WorldSession* s) uint32 Sessions = GetActiveAndQueuedSessionCount (); uint32 pLimit = GetPlayerAmountLimit (); - uint32 QueueSize = GetQueueSize (); //number of players in the queue + uint32 QueueSize = GetQueueSize (); //number of players in the queue //so we don't count the user trying to //login as a session and queue the socket that we are using @@ -243,10 +243,10 @@ World::AddSession_ (WorldSession* s) WorldPacket packet(SMSG_AUTH_RESPONSE, 1 + 4 + 1 + 4 + 1); packet << uint8 (AUTH_OK); - packet << uint32 (0); // unknown random value... - packet << uint8 (0); - packet << uint32 (0); - packet << uint8 (s->Expansion()); // 0 - normal, 1 - TBC, must be set in database manually for each account + packet << uint32 (0); // BillingTimeRemaining + packet << uint8 (0); // BillingPlanFlags + packet << uint32 (0); // BillingTimeRested + packet << uint8 (s->Expansion()); // 0 - normal, 1 - TBC, must be set in database manually for each account s->SendPacket (&packet); UpdateMaxSessionCounters (); @@ -254,7 +254,7 @@ World::AddSession_ (WorldSession* s) // Updates the population if (pLimit > 0) { - float popu = GetActiveSessionCount (); //updated number of users on the server + float popu = GetActiveSessionCount (); //updated number of users on the server popu /= pLimit; popu *= 2; loginDatabase.PExecute ("UPDATE realmlist SET population = '%f' WHERE id = '%d'", popu, realmID); @@ -281,10 +281,10 @@ void World::AddQueuedPlayer(WorldSession* sess) // The 1st SMSG_AUTH_RESPONSE needs to contain other info too. WorldPacket packet (SMSG_AUTH_RESPONSE, 1 + 4 + 1 + 4 + 1); packet << uint8 (AUTH_WAIT_QUEUE); - packet << uint32 (0); // unknown random value... - packet << uint8 (0); - packet << uint32 (0); - packet << uint8 (sess->Expansion()); // 0 - normal, 1 - TBC, must be set in database manually for each account + packet << uint32 (0); // BillingTimeRemaining + packet << uint8 (0); // BillingPlanFlags + packet << uint32 (0); // BillingTimeRested + packet << uint8 (sess->Expansion()); // 0 - normal, 1 - TBC, must be set in database manually for each account packet << uint32(GetQueuePos (sess)); sess->SendPacket (&packet); @@ -1048,7 +1048,7 @@ void World::SetInitialWorldSettings() ///- Clean up and pack instances sLog.outString( "Cleaning up instances..." ); - sInstanceSaveManager.CleanupInstances(); // must be called before `creature_respawn`/`gameobject_respawn` tables + sInstanceSaveManager.CleanupInstances(); // must be called before `creature_respawn`/`gameobject_respawn` tables sLog.outString( "Packing instances..." ); sInstanceSaveManager.PackInstances(); -- 2.11.4.GIT