Corrected NPC view constant verification (#4398)

* Fixes #4397.
* Corrected NPC view constant verification stopping at the first digit found resulting in invalid results.
Thanks to @Lemongrass3110!
This commit is contained in:
Aleos 2019-10-09 12:05:08 -04:00 committed by GitHub
parent 3c78691d2d
commit 995fb2a0a1
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
7 changed files with 10 additions and 26 deletions

View File

@ -2520,7 +2520,7 @@ static void npc_parsename(struct npc_data* nd, const char* name, const char* sta
* Support for using Constants in place of NPC View IDs.
*/
int npc_parseview(const char* w4, const char* start, const char* buffer, const char* filepath) {
int val = JT_FAKENPC, i = 0;
int i = 0;
char viewid[1024]; // Max size of name from const.txt, see read_constdb.
// Extract view ID / constant
@ -2533,36 +2533,21 @@ int npc_parseview(const char* w4, const char* start, const char* buffer, const c
safestrncpy(viewid, w4, i+=1);
char *pid;
int val = strtol(viewid, &pid, 0);
// Check if view id is not an ID (only numbers).
if(!npc_viewisid(viewid)) {
if (pid != nullptr && *pid != '\0') {
// Check if constant exists and get its value.
if(!script_get_constant(viewid, &val)) {
ShowWarning("npc_parseview: Invalid NPC constant '%s' specified in file '%s', line'%d'. Defaulting to INVISIBLE. \n", viewid, filepath, strline(buffer,start-buffer));
val = JT_INVISIBLE;
}
} else {
// NPC has an ID specified for view id.
val = atoi(w4);
}
return val;
}
/**
* Checks if given view is an ID or constant.
*/
bool npc_viewisid(const char * viewid)
{
if(atoi(viewid) != JT_FAKENPC) {
// Loop through view, looking for non-numeric character.
while (*viewid) {
if (ISDIGIT(*viewid++) == 0) return false;
}
}
return true;
}
/**
* Create a bare NPC object.
* @param m: Map ID

View File

@ -1212,7 +1212,6 @@ int npc_buysellsel(struct map_session_data* sd, int id, int type);
uint8 npc_buylist(struct map_session_data* sd, uint16 n, struct s_npc_buy_list *item_list);
uint8 npc_selllist(struct map_session_data* sd, int n, unsigned short *item_list);
void npc_parse_mob2(struct spawn_data* mob);
bool npc_viewisid(const char * viewid);
struct npc_data* npc_add_warp(char* name, short from_mapid, short from_x, short from_y, short xs, short ys, unsigned short to_mapindex, short to_x, short to_y);
int npc_globalmessage(const char* name,const char* mes);
const char *npc_get_script_event_name(int npce_index);