summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2014-02-11 17:32:46 -0200
committershennetsind <ind@henn.et>2014-02-11 17:32:46 -0200
commit71bd22ac878663f1f0a3e7c605532fd8b6babfdb (patch)
treeec21b87b45a2621f575ae7d419040d47fd8e7025
parent90a2c005e8ec14e4af480dcf2e0dbb5112debfde (diff)
downloadhercules-71bd22ac878663f1f0a3e7c605532fd8b6babfdb.tar.gz
hercules-71bd22ac878663f1f0a3e7c605532fd8b6babfdb.tar.bz2
hercules-71bd22ac878663f1f0a3e7c605532fd8b6babfdb.tar.xz
hercules-71bd22ac878663f1f0a3e7c605532fd8b6babfdb.zip
Fixed issue with referenced array operations
Did not affect write/read, except getarraysize and deletearray. Special Thanks to Haru! Signed-off-by: shennetsind <ind@henn.et>
-rw-r--r--src/map/script.c33
-rw-r--r--src/map/script.h6
2 files changed, 21 insertions, 18 deletions
diff --git a/src/map/script.c b/src/map/script.c
index 7ca6a7ddd..be346cb92 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -2609,7 +2609,7 @@ void* get_val2(struct script_state* st, int64 uid, struct DBMap** ref) {
**/
void script_array_ensure_zero(struct script_state *st, struct map_session_data *sd, int64 uid, struct DBMap** ref) {
const char *name = script->get_str(script_getvarid(uid));
- struct DBMap *src = script->array_src(st, sd ? sd : st->rid ? map->id2sd(st->rid) : NULL, name);\
+ struct DBMap *src = script->array_src(st, sd ? sd : st->rid ? map->id2sd(st->rid) : NULL, name, ref);\
struct script_array *sa = NULL;
bool insert = false;
@@ -2649,9 +2649,9 @@ void script_array_ensure_zero(struct script_state *st, struct map_session_data *
/**
* Returns array size by ID
**/
-unsigned int script_array_size(struct script_state *st, struct map_session_data *sd, const char *name) {
+unsigned int script_array_size(struct script_state *st, struct map_session_data *sd, const char *name, struct DBMap **ref) {
struct script_array *sa = NULL;
- struct DBMap *src = script->array_src(st, sd, name);
+ struct DBMap *src = script->array_src(st, sd, name, ref);
if( src )
sa = idb_get(src, script->search_str(name));
@@ -2661,15 +2661,15 @@ unsigned int script_array_size(struct script_state *st, struct map_session_data
/**
* Returns array's highest key (for that awful getarraysize implementation that doesn't really gets the array size)
**/
-unsigned int script_array_highest_key(struct script_state *st, struct map_session_data *sd, const char *name) {
+unsigned int script_array_highest_key(struct script_state *st, struct map_session_data *sd, const char *name, struct DBMap **ref) {
struct script_array *sa = NULL;
- struct DBMap *src = script->array_src(st, sd, name);
+ struct DBMap *src = script->array_src(st, sd, name, ref);
if( src ) {
int key = script->add_word(name);
- script->array_ensure_zero(st,sd,reference_uid(key, 0),NULL);
+ script->array_ensure_zero(st,sd,reference_uid(key, 0),ref);
if( ( sa = idb_get(src, key) ) ) {
unsigned int i, highest_key = 0;
@@ -2741,7 +2741,7 @@ void script_array_add_member(struct script_array *sa, unsigned int idx) {
* Obtains the source of the array database for this type and scenario
* Initializes such database when not yet initialised.
**/
-struct DBMap *script_array_src(struct script_state *st, struct map_session_data *sd, const char *name) {
+struct DBMap *script_array_src(struct script_state *st, struct map_session_data *sd, const char *name, struct DBMap **ref) {
struct DBMap **src = NULL;
switch( name[0] ) {
@@ -2755,7 +2755,10 @@ struct DBMap *script_array_src(struct script_state *st, struct map_session_data
src = &mapreg->array_db;
break;
case '.':/* npc/script */
- src = (name[1] == '@') ? &st->stack->array_function_db : &st->script->script_arrays_db;
+ if( ref )
+ src = (struct DBMap **)((char *)ref + sizeof(struct DBMap *));
+ else
+ src = (name[1] == '@') ? &st->stack->array_function_db : &st->script->script_arrays_db;
break;
case '\'':/* instance */
if( st->instance_id >= 0 ) {
@@ -4079,7 +4082,7 @@ void script_cleararray_pc(struct map_session_data* sd, const char* varname, void
key = script->add_str(varname);
- if( !(src = script->array_src(NULL,sd,varname) ) )
+ if( !(src = script->array_src(NULL,sd,varname,NULL) ) )
return;
if( value )
@@ -5791,7 +5794,7 @@ BUILDIN(getarraysize)
return false;// not a variable
}
- script_pushint(st, script->array_highest_key(st,st->rid ? script->rid2sd(st) : NULL,reference_getname(data)));
+ script_pushint(st, script->array_highest_key(st,st->rid ? script->rid2sd(st) : NULL,reference_getname(data),reference_getref(data)));
return true;
}
int script_array_index_cmp(const void *a, const void *b) {
@@ -5834,7 +5837,7 @@ BUILDIN(deletearray)
return true;// no player attached
}
- if( !(src = script->array_src(st,sd,name) ) ) {
+ if( !(src = script->array_src(st,sd,name, reference_getref(data)) ) ) {
ShowError("script:deletearray: not a array\n");
script->reportdata(data);
st->state = END;
@@ -5847,7 +5850,7 @@ BUILDIN(deletearray)
return true;// not a variable
}
- end = script->array_highest_key(st,sd,name);
+ end = script->array_highest_key(st,sd,name,reference_getref(data));
if( start >= end )
return true;// nothing to free
@@ -6247,8 +6250,8 @@ BUILDIN(checkweight2)
script_pushint(st,0);
return false;// not supported
}
- nb_it = script->array_highest_key(st,sd,reference_getname(data_it));
- nb_nb = script->array_highest_key(st,sd,reference_getname(data_nb));
+ nb_it = script->array_highest_key(st,sd,reference_getname(data_it),reference_getref(data_it));
+ nb_nb = script->array_highest_key(st,sd,reference_getname(data_nb),reference_getref(data_nb));
if(nb_it != nb_nb) {
ShowError("Size mistmatch: nb_it=%d, nb_nb=%d\n",nb_it,nb_nb);
fail = 1;
@@ -13875,7 +13878,7 @@ BUILDIN(implode)
}
//count chars
- array_size = script->array_highest_key(st,sd,name) - 1;
+ array_size = script->array_highest_key(st,sd,name,reference_getref(data)) - 1;
if(array_size == -1) {
//empty array check (AmsTaff)
diff --git a/src/map/script.h b/src/map/script.h
index 872c5bc31..3835a130b 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -679,13 +679,13 @@ struct script_interface {
/**
* Array Handling
**/
- struct DBMap *(*array_src) (struct script_state *st, struct map_session_data *sd, const char *name);
+ struct DBMap *(*array_src) (struct script_state *st, struct map_session_data *sd, const char *name, struct DBMap **ref);
void (*array_update) (struct DBMap **src, int64 num, bool empty);
void (*array_delete) (struct DBMap *src, struct script_array *sa);
void (*array_remove_member) (struct DBMap *src, struct script_array *sa, unsigned int idx);
void (*array_add_member) (struct script_array *sa, unsigned int idx);
- unsigned int (*array_size) (struct script_state *st, struct map_session_data *sd, const char *name);
- unsigned int (*array_highest_key) (struct script_state *st, struct map_session_data *sd, const char *name);
+ unsigned int (*array_size) (struct script_state *st, struct map_session_data *sd, const char *name, struct DBMap** ref);
+ unsigned int (*array_highest_key) (struct script_state *st, struct map_session_data *sd, const char *name, struct DBMap** ref);
int (*array_free_db) (DBKey key, DBData *data, va_list ap);
void (*array_ensure_zero) (struct script_state *st, struct map_session_data *sd, int64 uid, struct DBMap** ref);
/* */