viewing paste Unknown #12654 | Text

Posted on the
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50
int pc_setregistry_str(struct map_session_data *sd, int64 reg, const char *val) {
    struct script_reg_str *p = NULL;
    const char *regname = script->get_str( script_getvarid(reg) );
    unsigned int index = script_getvaridx(reg);
 
    if ( !pc->reg_load && !sd->vars_ok ) {
        ShowError("pc_setregistry_str : refusing to set %s until vars are received.\n", regname);
        return 0;
    }
 
    if( (p = i64db_get(sd->var_db, reg) ) ) {
        if( val[0] ) {
            if( p->value )
                aFree(p->value);
            else if ( index ) /* a entry that was deleted, so we reset */
                script->array_update(&sd->array_db,reg,false);
            p->value = aStrdup(val);
        } else {
            p->value = NULL;
            if( index )
                script->array_update(&sd->array_db,reg,true);
        }
        if( !pc->reg_load )
            p->flag.update = 1;/* either way, it will require either delete or replace */
    } else if( val[0] ) {
        DBData prev;
 
        if( index )
            script->array_update(&sd->array_db,reg,false);
 
        p = ers_alloc(pc->str_reg_ers, struct script_reg_str);
        
        p->value = aStrdup(val);
        if( !pc->reg_load )
            p->flag.update = 1;
        p->flag.type = 1;
        
        if( sd->var_db->put(sd->var_db,DB->i642key(reg),DB->ptr2data(p),&prev) ) {
            p = DB->data2ptr(&prev);
            if( p->value )
                aFree(p->value);
            ers_free(pc->str_reg_ers, p);
        }
    }
    
    if( !pc->reg_load && p )
        sd->vars_dirty = true;
    
    return 1;
}
Viewed 689 times, submitted by Xgear.