From 995fb2a0a19fee574dd72c1f2ea61870f973b18a Mon Sep 17 00:00:00 2001 From: Aleos Date: Wed, 9 Oct 2019 12:05:08 -0400 Subject: [PATCH] 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! --- npc/jobs/1-1e/ninja.txt | 2 +- npc/other/arena/arena_party.txt | 2 +- npc/quests/gunslinger_quests.txt | 2 +- npc/quests/quests_lighthalzen.txt | 2 +- npc/re/instances/MorseCave.txt | 2 +- src/map/npc.cpp | 25 +++++-------------------- src/map/npc.hpp | 1 - 7 files changed, 10 insertions(+), 26 deletions(-) diff --git a/npc/jobs/1-1e/ninja.txt b/npc/jobs/1-1e/ninja.txt index a8d27bf6fc..ea7a09dd5a 100644 --- a/npc/jobs/1-1e/ninja.txt +++ b/npc/jobs/1-1e/ninja.txt @@ -374,7 +374,7 @@ que_ng,30,65,3 script Kuuga Gai#nq 730,{ } } -einbroch,184,194,3 script Suspicious Man#nq 881,{ +einbroch,184,194,3 script Suspicious Man#nq 881,{ if (NINJ_Q == 1) { mes "[Suspicious Man]"; mes "I've traveled to many"; diff --git a/npc/other/arena/arena_party.txt b/npc/other/arena/arena_party.txt index f7d5a88845..311b71bd24 100644 --- a/npc/other/arena/arena_party.txt +++ b/npc/other/arena/arena_party.txt @@ -40,7 +40,7 @@ OnStart: end; } -prt_are_in,76,87,3 script Helper#party 67,4,4,{ +prt_are_in,76,87,3 script Helper#party 67,4,4,{ if($arn_partywait == 0) { set $arn_partywait,1; emotion ET_SURPRISE; diff --git a/npc/quests/gunslinger_quests.txt b/npc/quests/gunslinger_quests.txt index a0eb05a917..a33e515353 100644 --- a/npc/quests/gunslinger_quests.txt +++ b/npc/quests/gunslinger_quests.txt @@ -383,7 +383,7 @@ SubGarrison_: } } -lighthalzen,322,247,6 script Ravey 86,{ +lighthalzen,322,247,6 script Ravey 86,{ if(gun_gs == 2) { diff --git a/npc/quests/quests_lighthalzen.txt b/npc/quests/quests_lighthalzen.txt index 331574d275..12544527c0 100644 --- a/npc/quests/quests_lighthalzen.txt +++ b/npc/quests/quests_lighthalzen.txt @@ -11016,7 +11016,7 @@ lighthalzen,141,162,3 script Old Man#reken 85,{ close; } -einbroch,55,52,3 script Laboratory Guard#reken 852,{ +einbroch,55,52,3 script Laboratory Guard#reken 852,{ if(lhz_rekenber == 3) { diff --git a/npc/re/instances/MorseCave.txt b/npc/re/instances/MorseCave.txt index 7d90798e34..1ff95d7924 100644 --- a/npc/re/instances/MorseCave.txt +++ b/npc/re/instances/MorseCave.txt @@ -383,7 +383,7 @@ OnMobDead: } -1@rev,34,126,4 script Grim Reaper Ankou#RZ Event_3 3029,{ end; } +1@rev,34,126,4 script Grim Reaper Ankou#RZ Event_3 3029,{ end; } 1@rev,112,126,4 duplicate(Grim Reaper Ankou#RZ Event_3) Grim Reaper Ankou#RZ Event_4 3029 1@rev,34,55,4 duplicate(Grim Reaper Ankou#RZ Event_3) Grim Reaper Ankou#RZ Event_5 3029 1@rev,112,48,4 duplicate(Grim Reaper Ankou#RZ Event_3) Grim Reaper Ankou#RZ Event_6 3029 diff --git a/src/map/npc.cpp b/src/map/npc.cpp index b0523ecfc0..c33c414a80 100644 --- a/src/map/npc.cpp +++ b/src/map/npc.cpp @@ -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 diff --git a/src/map/npc.hpp b/src/map/npc.hpp index 62bd807226..35773ca703 100644 --- a/src/map/npc.hpp +++ b/src/map/npc.hpp @@ -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);