Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: support outfit crashes on login #2526

Merged
merged 21 commits into from
Jul 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
bf74b3e
Check and changes if you are logged with support/team outfit (in clie…
elsongabriel Apr 5, 2024
15861aa
resolving crash.
elsongabriel Apr 8, 2024
d30710c
Moved function to check support outfit to data path.
elsongabriel Apr 23, 2024
ea1b739
Created config to disable support outfit selector on customize charac…
elsongabriel Apr 23, 2024
2509fa9
Improved checks and removed redundant code.
elsongabriel Apr 23, 2024
d4f237f
Merge branch 'main' into fix/support-outfit-crashs
elsongabriel Apr 25, 2024
be17202
Merge branch 'main' into fix/support-outfit-crashs
elsongabriel Apr 26, 2024
3948236
Merge branch 'main' into fix/support-outfit-crashs
elsongabriel Apr 29, 2024
d189c2a
Merge branch 'main' into fix/support-outfit-crashs
elsongabriel May 8, 2024
8562cc0
Merge branch 'main' into fix/support-outfit-crashs
elsongabriel May 8, 2024
ce5d167
Merge branch 'main' into fix/support-outfit-crashs
elsongabriel May 12, 2024
4f330bb
Merge branch 'main' into fix/support-outfit-crashs
elsongabriel May 16, 2024
e4078b5
Merge branch 'main' into fix/support-outfit-crashs
elsongabriel May 27, 2024
f3c5d26
Merge branch 'main' into fix/support-outfit-crashs
elsongabriel May 30, 2024
d9a206b
Merge branch 'main' into fix/support-outfit-crashs
elsongabriel Jun 6, 2024
16cc2e5
Merge branch 'main' into fix/support-outfit-crashs
elsongabriel Jun 12, 2024
a61062c
Merge branch 'main' into fix/support-outfit-crashs
elsongabriel Jun 23, 2024
87b5a52
Merge branch 'main' into fix/support-outfit-crashs
elsongabriel Jun 26, 2024
37dd41d
Merge branch 'main' into fix/support-outfit-crashs
elsongabriel Jul 2, 2024
a545808
improved function name.
elsongabriel Jul 2, 2024
f5bcc3a
Merge branch 'main' into fix/support-outfit-crashs
elsongabriel Jul 5, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions config.lua.dist
Original file line number Diff line number Diff line change
Expand Up @@ -254,6 +254,7 @@ onlyPremiumAccount = false
-- NOTE: startStreakLevel will make a reward streak level for new players who never logged in
-- NOTE: if showLootsInBestiary is true, will cause all loots to be shown in the bestiary even if the player has not reached the required number of kills
-- NOTE: minTownIdToBankTransfer blocks towns less than defined from receiving money transfers
-- NOTE: enableSupportOutfit enable GODS and GMS to select support outfit (gamemaster, customer support or community manager)
stashMoving = false
depotChest = 4
autoLoot = false
Expand All @@ -273,6 +274,7 @@ enablePlayerPutItemInAmmoSlot = false
startStreakLevel = 0
showLootsInBestiary = false
minTownIdToBankTransfer = 3
enableSupportOutfit = true

-- Teleport summon
-- Set to true will never remove the summon
Expand Down
8 changes: 8 additions & 0 deletions data/scripts/creaturescripts/player/login.lua
Original file line number Diff line number Diff line change
Expand Up @@ -169,6 +169,14 @@ function playerLoginGlobal.onLogin(player)
onMovementRemoveProtection(playerId, player:getPosition(), 10)
end

-- Change support outfit to a normal outfit to open customize character without crashes
local playerOutfit = player:getOutfit()
if table.contains({ 75, 266, 302 }, playerOutfit.lookType) then
playerOutfit.lookType = 136
playerOutfit.lookAddons = 0
player:setOutfit(playerOutfit)
end

player:initializeLoyaltySystem()
player:registerEvent("PlayerDeath")
player:registerEvent("DropLoot")
Expand Down
1 change: 1 addition & 0 deletions src/config/config_enums.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -63,6 +63,7 @@ enum ConfigKey_t : uint16_t {
DISCORD_WEBHOOK_URL,
EMOTE_SPELLS,
ENABLE_PLAYER_PUT_ITEM_IN_AMMO_SLOT,
ENABLE_SUPPORT_OUTFIT,
EX_ACTIONS_DELAY_INTERVAL,
EXP_FROM_PLAYERS_LEVEL_RANGE,
EXPERIENCE_FROM_PLAYERS,
Expand Down
1 change: 1 addition & 0 deletions src/config/configmanager.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -97,6 +97,7 @@ bool ConfigManager::load() {
loadBoolConfig(L, DISCORD_SEND_FOOTER, "discordSendFooter", true);
loadBoolConfig(L, EMOTE_SPELLS, "emoteSpells", false);
loadBoolConfig(L, ENABLE_PLAYER_PUT_ITEM_IN_AMMO_SLOT, "enablePlayerPutItemInAmmoSlot", false);
loadBoolConfig(L, ENABLE_SUPPORT_OUTFIT, "enableSupportOutfit", true);
loadBoolConfig(L, EXPERIENCE_FROM_PLAYERS, "experienceByKillingPlayers", false);
loadBoolConfig(L, FORCE_MONSTERTYPE_LOAD, "forceMonsterTypesOnLoad", true);
loadBoolConfig(L, FREE_PREMIUM, "freePremium", false);
Expand Down
4 changes: 4 additions & 0 deletions src/creatures/creature.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,10 @@ class Creature : virtual public Thing, public SharedObject {
const Outfit_t getDefaultOutfit() const {
return defaultOutfit;
}
bool isWearingSupportOutfit() const {
auto outfit = currentOutfit.lookType;
return outfit == 75 || outfit == 266 || outfit == 302;
}
bool isInvisible() const;
ZoneType_t getZoneType() {
if (getTile()) {
Expand Down
4 changes: 4 additions & 0 deletions src/creatures/players/player.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5818,6 +5818,10 @@ bool Player::toggleMount(bool mount) {
return false;
}

if (isWearingSupportOutfit()) {
return false;
}

if (mount) {
if (isMounted()) {
return false;
Expand Down
7 changes: 6 additions & 1 deletion src/game/game.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4263,7 +4263,7 @@ void Game::playerSetShowOffSocket(uint32_t playerId, Outfit_t &outfit, const Pos
}

const auto mount = mounts.getMountByClientID(outfit.lookMount);
if (!mount || !player->hasMount(mount)) {
if (!mount || !player->hasMount(mount) || player->isWearingSupportOutfit()) {
outfit.lookMount = 0;
}

Expand Down Expand Up @@ -5960,6 +5960,11 @@ void Game::playerChangeOutfit(uint32_t playerId, Outfit_t outfit, uint8_t isMoun
return;
}

if (player->isWearingSupportOutfit()) {
outfit.lookMount = 0;
isMountRandomized = 0;
}

player->setRandomMount(isMountRandomized);

if (isMountRandomized && outfit.lookMount != 0 && player->hasAnyMount()) {
Expand Down
55 changes: 30 additions & 25 deletions src/server/network/protocol/protocolgame.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -3203,15 +3203,22 @@ void ProtocolGame::sendCreatureOutfit(std::shared_ptr<Creature> creature, const
return;
}

Outfit_t newOutfit = outfit;
if (player->isWearingSupportOutfit()) {
player->setCurrentMount(0);
newOutfit.lookMount = 0;
}

NetworkMessage msg;
msg.addByte(0x8E);
msg.add<uint32_t>(creature->getID());
AddOutfit(msg, outfit);
if (!oldProtocol && outfit.lookMount != 0) {
msg.addByte(outfit.lookMountHead);
msg.addByte(outfit.lookMountBody);
msg.addByte(outfit.lookMountLegs);
msg.addByte(outfit.lookMountFeet);
AddOutfit(msg, newOutfit);

if (!oldProtocol && newOutfit.lookMount != 0) {
msg.addByte(newOutfit.lookMountHead);
msg.addByte(newOutfit.lookMountBody);
msg.addByte(newOutfit.lookMountLegs);
msg.addByte(newOutfit.lookMountFeet);
}
writeToOutputBuffer(msg);
}
Expand Down Expand Up @@ -6949,15 +6956,23 @@ void ProtocolGame::sendOutfitWindow() {
NetworkMessage msg;
msg.addByte(0xC8);

if (oldProtocol) {
Outfit_t currentOutfit = player->getDefaultOutfit();
Outfit_t currentOutfit = player->getDefaultOutfit();
auto isSupportOutfit = player->isWearingSupportOutfit();
bool mounted = false;

if (!isSupportOutfit) {
const auto currentMount = g_game().mounts.getMountByID(player->getLastMount());
if (currentMount) {
mounted = (currentOutfit.lookMount == currentMount->clientId);
currentOutfit.lookMount = currentMount->clientId;
}
} else {
currentOutfit.lookMount = 0;
}

AddOutfit(msg, currentOutfit);
AddOutfit(msg, currentOutfit);

if (oldProtocol) {
std::vector<ProtocolOutfit> protocolOutfits;
const auto outfits = Outfits::getInstance().getOutfits(player->getSex());
protocolOutfits.reserve(outfits.size());
Expand Down Expand Up @@ -6998,20 +7013,10 @@ void ProtocolGame::sendOutfitWindow() {
return;
}

bool mounted = false;
Outfit_t currentOutfit = player->getDefaultOutfit();
const auto currentMount = g_game().mounts.getMountByID(player->getLastMount());
if (currentMount) {
mounted = (currentOutfit.lookMount == currentMount->clientId);
currentOutfit.lookMount = currentMount->clientId;
}

AddOutfit(msg, currentOutfit);

msg.addByte(currentOutfit.lookMountHead);
msg.addByte(currentOutfit.lookMountBody);
msg.addByte(currentOutfit.lookMountLegs);
msg.addByte(currentOutfit.lookMountFeet);
msg.addByte(isSupportOutfit ? 0 : currentOutfit.lookMountHead);
msg.addByte(isSupportOutfit ? 0 : currentOutfit.lookMountBody);
msg.addByte(isSupportOutfit ? 0 : currentOutfit.lookMountLegs);
msg.addByte(isSupportOutfit ? 0 : currentOutfit.lookMountFeet);
msg.add<uint16_t>(currentOutfit.lookFamiliarsType);

auto startOutfits = msg.getBufferPosition();
Expand All @@ -7020,7 +7025,7 @@ void ProtocolGame::sendOutfitWindow() {
uint16_t outfitSize = 0;
msg.skipBytes(2);

if (player->isAccessPlayer()) {
if (player->isAccessPlayer() && g_configManager().getBoolean(ENABLE_SUPPORT_OUTFIT, __FUNCTION__)) {
msg.add<uint16_t>(75);
msg.addString("Gamemaster", "ProtocolGame::sendOutfitWindow - Gamemaster");
msg.addByte(0);
Expand Down Expand Up @@ -7144,7 +7149,7 @@ void ProtocolGame::sendOutfitWindow() {
msg.addByte(mounted ? 0x01 : 0x00);

// Version 12.81 - Random mount 'bool'
msg.addByte(player->isRandomMounted() ? 0x01 : 0x00);
msg.addByte(isSupportOutfit ? 0x00 : (player->isRandomMounted() ? 0x01 : 0x00));

writeToOutputBuffer(msg);
}
Expand Down
Loading