From a028a74ae527ddee74449053b5b91b55f273b867 Mon Sep 17 00:00:00 2001 From: Sandro Junior Date: Mon, 6 Dec 2021 10:59:09 -0300 Subject: [PATCH] Fix SC_WINKCHARM behavior (#6384) Adds a check to prevent func unit_walktoxy_timer to use DIR_CENTER direction (which has -1 value) on SC_WINKCHARMed mobs. Using this direction may cause dump values when accessing dirx or diry array; Fixed timer mismatchs reported in https://github.com/rathena/rathena/issues/6371#issuecomment-982108186 Fixes #6371 Co-authored-by: Lemongrass3110 --- src/map/unit.cpp | 22 +++++++++++++++------- 1 file changed, 15 insertions(+), 7 deletions(-) diff --git a/src/map/unit.cpp b/src/map/unit.cpp index 36c62ee668..6c160b46b1 100644 --- a/src/map/unit.cpp +++ b/src/map/unit.cpp @@ -139,8 +139,14 @@ int unit_walktoxy_sub(struct block_list *bl) i = status_get_speed(bl)*MOVE_DIAGONAL_COST/MOVE_COST; else i = status_get_speed(bl); - if( i > 0) + if( i > 0 ){ + if( ud->walktimer != INVALID_TIMER ){ + delete_timer( ud->walktimer, unit_walktoxy_timer ); + ud->walktimer = INVALID_TIMER; + } ud->walktimer = add_timer(gettick()+i,unit_walktoxy_timer,bl->id,i); + } + return 1; } @@ -388,13 +394,12 @@ static TIMER_FUNC(unit_walktoxy_timer) if(ud->walkpath.path_pos>=ud->walkpath.path_len) return 0; - if(ud->walkpath.path[ud->walkpath.path_pos]>=DIR_MAX) - return 1; - - int x = bl->x; - int y = bl->y; - enum directions dir = ud->walkpath.path[ud->walkpath.path_pos]; + + if( dir <= DIR_CENTER || dir >= DIR_MAX ){ + return 0; + } + ud->dir = dir; int dx = dirx[dir]; @@ -420,6 +425,9 @@ static TIMER_FUNC(unit_walktoxy_timer) case BL_NPC: nd = BL_CAST(BL_NPC, bl); break; } + int x = bl->x; + int y = bl->y; + //Monsters will walk into an icewall from the west and south if they already started walking if(map_getcell(bl->m,x+dx,y+dy,CELL_CHKNOPASS) && (icewall_walk_block == 0 || dx < 0 || dy < 0 || !map_getcell(bl->m,x+dx,y+dy,CELL_CHKICEWALL)))