浏览代码

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 <lemongrass@kstp.at>
Sandro Junior 3 年之前
父节点
当前提交
a028a74ae5
共有 1 个文件被更改,包括 14 次插入6 次删除
  1. 14 6
      src/map/unit.cpp

+ 14 - 6
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;
+	enum directions dir = ud->walkpath.path[ud->walkpath.path_pos];
 
-	int x = bl->x;
-	int y = bl->y;
+	if( dir <= DIR_CENTER || dir >= DIR_MAX ){
+		return 0;
+	}
 
-	enum directions dir = ud->walkpath.path[ud->walkpath.path_pos];
 	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)))