From 8f049e98306b7eaae81ea7df0a837d91ef21d438 Mon Sep 17 00:00:00 2001 From: ai4rei Date: Tue, 21 Dec 2010 21:30:46 +0000 Subject: * Fixed dynamic shop arrays @bought_nameid, @bought_quantity, @sold_nameid and @sold_quantity not getting reset to zero before use, thus providing attached script with wrong/old data, if it did not clear them by itself in previous call (bugreport:1574, since r5841). git-svn-id: https://rathena.svn.sourceforge.net/svnroot/rathena/trunk@14611 54d463be-8e91-2dee-dedb-b68131a5f0ec --- Changelog-Trunk.txt | 1 + src/map/npc.c | 12 ++++++++++++ src/map/script.c | 32 ++++++++++++++++++++++++++++++++ src/map/script.h | 2 ++ 4 files changed, 47 insertions(+) diff --git a/Changelog-Trunk.txt b/Changelog-Trunk.txt index 36e049a69..89064891a 100644 --- a/Changelog-Trunk.txt +++ b/Changelog-Trunk.txt @@ -1,6 +1,7 @@ Date Added 2010/12/21 + * Fixed dynamic shop arrays @bought_nameid, @bought_quantity, @sold_nameid and @sold_quantity not getting reset to zero before use, thus providing attached script with wrong/old data, if it did not clear them by itself in previous call (bugreport:1574, since r5841). [Ai4rei] * Removed 'strsignal' forward-declaration from 'sig' plugin to prevent random gcc distributions from failing to compile due to mismatched declaration already present in (bugreport:4644, topic:262284, follow up to r14591). [Ai4rei] - Removed WIN32 conditions in non-WIN32 code in 'sig' plugin (follow up to r4380). 2010/12/19 diff --git a/src/map/npc.c b/src/map/npc.c index 0b16aa6f9..d210bea94 100644 --- a/src/map/npc.c +++ b/src/map/npc.c @@ -1144,6 +1144,11 @@ static int npc_buylist_sub(struct map_session_data* sd, int n, unsigned short* i int i; int regkey = add_str("@bought_nameid"); int regkey2 = add_str("@bought_quantity"); + + // discard old contents + script_cleararray_pc(sd, "@bought_nameid", (void*)0); + script_cleararray_pc(sd, "@bought_quantity", (void*)0); + snprintf(npc_ev, ARRAYLENGTH(npc_ev), "%s::OnBuyItem", nd->exname); for(i=0;imaster_nd; //For OnSell triggers. + if( nd ) + { + // discard old contents + script_cleararray_pc(sd, "@sold_nameid", (void*)0); + script_cleararray_pc(sd, "@sold_quantity", (void*)0); + } + for(i=0,z=0;istatus.char_id); + return; + } + + key = add_str(varname); + + if( is_string_variable(varname) ) + { + for( idx = 0; idx < SCRIPT_MAX_ARRAYSIZE; idx++ ) + { + pc_setregstr(sd, reference_uid(key, idx), (const char*)value); + } + } + else + { + for( idx = 0; idx < SCRIPT_MAX_ARRAYSIZE; idx++ ) + { + pc_setreg(sd, reference_uid(key, idx), (int)value); + } + } +} + + /*========================================== * I—¹ *------------------------------------------*/ diff --git a/src/map/script.h b/src/map/script.h index 9bc697e98..d95ecbbb2 100644 --- a/src/map/script.h +++ b/src/map/script.h @@ -167,6 +167,8 @@ struct DBMap* script_get_label_db(void); struct DBMap* script_get_userfunc_db(void); void script_run_autobonus(const char *autobonus,int id, int pos); +void script_cleararray_pc(struct map_session_data* sd, const char* varname, void* value); + int script_config_read(char *cfgName); int do_init_script(void); int do_final_script(void); -- cgit v1.2.3-60-g2f50