From 92722db3ab02cbfb4bf5395563929fae9d3b611d Mon Sep 17 00:00:00 2001 From: Vincent Stumpf Date: Mon, 10 Jun 2024 12:11:19 -0700 Subject: [PATCH] Fix dynamic npc timer mismatch (#8265) * Fix dynamic npc timer mismatch Fixes #8241 This adds some missing placement news that I'm surprised hasn't blown up yet. --- src/map/buyingstore.cpp | 1 + src/map/mob.cpp | 5 +++++ src/map/status.cpp | 23 ++++++++++++++++++++--- src/map/status.hpp | 2 ++ src/map/vending.cpp | 1 + 5 files changed, 29 insertions(+), 3 deletions(-) diff --git a/src/map/buyingstore.cpp b/src/map/buyingstore.cpp index 4e03d54a89..65c6ac15f7 100644 --- a/src/map/buyingstore.cpp +++ b/src/map/buyingstore.cpp @@ -703,6 +703,7 @@ void do_init_buyingstore_autotrade( void ) { // initialize player CREATE(at->sd, map_session_data, 1); // TODO: Dont use Memory Manager allocation anymore and rely on the C++ container + new (at->sd) map_session_data(); pc_setnewpc(at->sd, at->account_id, at->char_id, 0, gettick(), at->sex, 0); at->sd->state.autotrade = 1|4; if (battle_config.autotrade_monsterignore) diff --git a/src/map/mob.cpp b/src/map/mob.cpp index 521fd7237c..074a86cb70 100644 --- a/src/map/mob.cpp +++ b/src/map/mob.cpp @@ -191,6 +191,7 @@ void mvptomb_create(struct mob_data *md, char *killer, time_t time) mvptomb_destroy(md); CREATE(nd, struct npc_data, 1); + new (nd) npc_data(); nd->bl.id = md->tomb_nid = npc_get_new_npc_id(); @@ -210,6 +211,10 @@ void mvptomb_create(struct mob_data *md, char *killer, time_t time) nd->u.tomb.kill_time = time; nd->u.tomb.spawn_timer = INVALID_TIMER; + nd->dynamicnpc.owner_char_id = 0; + nd->dynamicnpc.last_interaction = 0; + nd->dynamicnpc.removal_tid = INVALID_TIMER; + if (killer) safestrncpy(nd->u.tomb.killer_name, killer, NAME_LENGTH); else diff --git a/src/map/status.cpp b/src/map/status.cpp index 81fd8783e6..165ddfcfa9 100644 --- a/src/map/status.cpp +++ b/src/map/status.cpp @@ -1143,6 +1143,25 @@ void StatusDatabase::removeByStatusFlag(block_list *bl, std::vectoroption = OPTION_NOTHING; + this->opt3 = OPT3_NORMAL; + this->opt1 = OPT1_NONE; + this->opt2 = OPT2_NONE; + this->count = 0; + this->lastEffect = SC_NONE; + this->lastEffectTimer = INVALID_TIMER; + this->cant = {}; + this->comet_x = 0; + this->comet_y = 0; +#ifndef RENEWAL + this->sg_counter = 0; +#endif + std::fill( std::begin( this->data ), std::end( this->data ), nullptr ); + this->lastStatus = { SC_NONE, nullptr }; +} + /** * Accessor for a status_change_entry in a status_change */ @@ -9406,9 +9425,7 @@ void status_change_init(struct block_list *bl) { status_change *sc = status_get_sc(bl); nullpo_retv(sc); - memset(sc, 0, sizeof (status_change)); - sc->lastEffect = SC_NONE; - sc->lastEffectTimer = INVALID_TIMER; + new (sc) status_change(); } /*========================================== [Playtester] diff --git a/src/map/status.hpp b/src/map/status.hpp index 2d0d03fb0c..3b77ae7648 100644 --- a/src/map/status.hpp +++ b/src/map/status.hpp @@ -3291,6 +3291,8 @@ private: std::pair lastStatus; // last-fetched status public: + status_change(); + status_change_entry * getSCE(enum sc_type type); status_change_entry * getSCE(uint32 type); status_change_entry * createSCE(enum sc_type type); diff --git a/src/map/vending.cpp b/src/map/vending.cpp index 15569872a8..b25631f0f0 100755 --- a/src/map/vending.cpp +++ b/src/map/vending.cpp @@ -612,6 +612,7 @@ void do_init_vending_autotrade(void) // initialize player CREATE(at->sd, map_session_data, 1); // TODO: Dont use Memory Manager allocation anymore and rely on the C++ container + new (at->sd) map_session_data(); pc_setnewpc(at->sd, at->account_id, at->char_id, 0, gettick(), at->sex, 0); at->sd->state.autotrade = 1|2; if (battle_config.autotrade_monsterignore)