summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--npc/dev/test.txt2
-rw-r--r--src/map/atcommand.c20
-rw-r--r--src/map/battleground.c18
-rw-r--r--src/map/channel.c2
-rw-r--r--src/map/clif.c50
-rw-r--r--src/map/duel.c4
-rw-r--r--src/map/intif.c4
-rw-r--r--src/map/mapreg_sql.c2
-rw-r--r--src/map/mob.c4
-rw-r--r--src/map/npc.c4
-rw-r--r--src/map/pc.c71
-rw-r--r--src/map/script.c187
-rw-r--r--src/map/script.h2
-rw-r--r--src/map/skill.c16
-rw-r--r--src/plugins/HPMHooking/HPMHooking.Defs.inc2
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc4
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc1
-rw-r--r--src/plugins/HPMHooking/HPMHooking_map.Hooks.inc27
18 files changed, 255 insertions, 165 deletions
diff --git a/npc/dev/test.txt b/npc/dev/test.txt
index 036a94916..bdbc52ed4 100644
--- a/npc/dev/test.txt
+++ b/npc/dev/test.txt
@@ -762,7 +762,7 @@ function script HerculesSelfTestHelper {
callsub(OnCheck, "Getdatatype (numeric variable)", getdatatype(.@x), DATATYPE_INT | DATATYPE_VAR);
callsub(OnCheck, "Getdatatype (string variable)", getdatatype(.@x$), DATATYPE_STR | DATATYPE_VAR);
callsub(OnCheck, "Getdatatype (label)", getdatatype(OnTestGetdatatype), DATATYPE_LABEL);
- //callsub(OnCheck, "Getdatatype (constant)", getdatatype(DATATYPE_CONST), DATATYPE_CONST); // FIXME
+ callsub(OnCheck, "Getdatatype (constant)", getdatatype(DATATYPE_CONST), DATATYPE_INT | DATATYPE_CONST);
callsub(OnCheck, "Getdatatype (returned integer)", getdatatype(callsub(OnTestReturnValue, 5)), DATATYPE_INT);
callsub(OnCheck, "Getdatatype (returned string)", getdatatype(callsub(OnTestReturnValue, "foo")), DATATYPE_STR | DATATYPE_CONST);
callsub(OnCheck, "Getdatatype (getarg default value)", callsub(OnTestGetdatatypeDefault), DATATYPE_INT);
diff --git a/src/map/atcommand.c b/src/map/atcommand.c
index 02b099742..6522f3013 100644
--- a/src/map/atcommand.c
+++ b/src/map/atcommand.c
@@ -8738,19 +8738,19 @@ ACMD(set)
const char *str = NULL;
switch (reg[0]) {
case '@':
- str = pc->readregstr(sd, script->add_str(reg));
+ str = pc->readregstr(sd, script->add_variable(reg));
break;
case '$':
- str = mapreg->readregstr(script->add_str(reg));
+ str = mapreg->readregstr(script->add_variable(reg));
break;
case '#':
if (reg[1] == '#')
- str = pc_readaccountreg2str(sd, script->add_str(reg));// global
+ str = pc_readaccountreg2str(sd, script->add_variable(reg));// global
else
- str = pc_readaccountregstr(sd, script->add_str(reg));// local
+ str = pc_readaccountregstr(sd, script->add_variable(reg));// local
break;
default:
- str = pc_readglobalreg_str(sd, script->add_str(reg));
+ str = pc_readglobalreg_str(sd, script->add_variable(reg));
break;
}
if (str == NULL || str[0] == '\0') {
@@ -8766,19 +8766,19 @@ ACMD(set)
data->type = C_INT;
switch( reg[0] ) {
case '@':
- data->u.num = pc->readreg(sd, script->add_str(reg));
+ data->u.num = pc->readreg(sd, script->add_variable(reg));
break;
case '$':
- data->u.num = mapreg->readreg(script->add_str(reg));
+ data->u.num = mapreg->readreg(script->add_variable(reg));
break;
case '#':
if( reg[1] == '#' )
- data->u.num = pc_readaccountreg2(sd, script->add_str(reg));// global
+ data->u.num = pc_readaccountreg2(sd, script->add_variable(reg));// global
else
- data->u.num = pc_readaccountreg(sd, script->add_str(reg));// local
+ data->u.num = pc_readaccountreg(sd, script->add_variable(reg));// local
break;
default:
- data->u.num = pc_readglobalreg(sd, script->add_str(reg));
+ data->u.num = pc_readglobalreg(sd, script->add_variable(reg));
break;
}
}
diff --git a/src/map/battleground.c b/src/map/battleground.c
index 4bedc2a00..c2772a2b9 100644
--- a/src/map/battleground.c
+++ b/src/map/battleground.c
@@ -615,7 +615,7 @@ static void bg_match_over(struct bg_arena *arena, bool canceled)
if (canceled)
clif->messagecolor_self(sd->fd, COLOR_RED, "BG Match Canceled: not enough players");
else
- pc_setglobalreg(sd, script->add_str(arena->delay_var), (unsigned int)time(NULL));
+ pc_setglobalreg(sd, script->add_variable(arena->delay_var), (unsigned int)time(NULL));
}
arena->begin_timer = INVALID_TIMER;
@@ -654,8 +654,8 @@ static void bg_begin(struct bg_arena *arena)
bg->afk_timer_id = timer->add(timer->gettick()+10000,bg->afk_timer,0,0);
/* TODO: make this a arena-independent var? or just .@? */
- mapreg->setreg(script->add_str("$@bg_queue_id"),arena->queue_id);
- mapreg->setregstr(script->add_str("$@bg_delay_var$"),bg->gdelay_var);
+ mapreg->setreg(script->add_variable("$@bg_queue_id"),arena->queue_id);
+ mapreg->setregstr(script->add_variable("$@bg_delay_var$"),bg->gdelay_var);
count = 0;
for (i = 0; i < VECTOR_LENGTH(queue->entries); i++) {
@@ -664,20 +664,20 @@ static void bg_begin(struct bg_arena *arena)
if (sd == NULL || sd->bg_queue.ready != 1)
continue;
- mapreg->setreg(reference_uid(script->add_str("$@bg_member"), count), sd->status.account_id);
- mapreg->setreg(reference_uid(script->add_str("$@bg_member_group"), count),
+ mapreg->setreg(reference_uid(script->add_variable("$@bg_member"), count), sd->status.account_id);
+ mapreg->setreg(reference_uid(script->add_variable("$@bg_member_group"), count),
sd->bg_queue.type == BGQT_GUILD ? sd->status.guild_id :
sd->bg_queue.type == BGQT_PARTY ? sd->status.party_id :
0
);
- mapreg->setreg(reference_uid(script->add_str("$@bg_member_type"), count),
+ mapreg->setreg(reference_uid(script->add_variable("$@bg_member_type"), count),
sd->bg_queue.type == BGQT_GUILD ? 1 :
sd->bg_queue.type == BGQT_PARTY ? 2 :
0
);
count++;
}
- mapreg->setreg(script->add_str("$@bg_member_size"),count);
+ mapreg->setreg(script->add_variable("$@bg_member_size"),count);
npc->event_do(arena->npc_event);
}
@@ -857,7 +857,7 @@ static enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, str
tsec = (unsigned int)time(NULL);
- if ( ( tick = pc_readglobalreg(sd, script->add_str(bg->gdelay_var)) ) && tsec < tick ) {
+ if ( ( tick = pc_readglobalreg(sd, script->add_variable(bg->gdelay_var)) ) && tsec < tick ) {
char response[100];
if( (tick-tsec) > 60 )
sprintf(response, "You are a deserter! Wait %u minute(s) before you can apply again", (tick - tsec) / 60);
@@ -867,7 +867,7 @@ static enum BATTLEGROUNDS_QUEUE_ACK bg_canqueue(struct map_session_data *sd, str
return BGQA_FAIL_DESERTER;
}
- if ( ( tick = pc_readglobalreg(sd, script->add_str(arena->delay_var)) ) && tsec < tick ) {
+ if ( ( tick = pc_readglobalreg(sd, script->add_variable(arena->delay_var)) ) && tsec < tick ) {
char response[100];
if( (tick-tsec) > 60 )
sprintf(response, "You can't reapply to this arena so fast. Apply to the different arena or wait %u minute(s)", (tick - tsec) / 60);
diff --git a/src/map/channel.c b/src/map/channel.c
index 3bb2016d8..f1946385d 100644
--- a/src/map/channel.c
+++ b/src/map/channel.c
@@ -290,7 +290,7 @@ static void channel_send(struct channel_data *chan, struct map_session_data *sd,
for (i = 0; i < MAX_EVENTQUEUE; i++) {
if (chan->handlers[i][0] != '\0') {
- pc->setregstr(sd, script->add_str("@channelmes$"), msg);
+ pc->setregstr(sd, script->add_variable("@channelmes$"), msg);
npc->event(sd, chan->handlers[i], 0);
}
}
diff --git a/src/map/clif.c b/src/map/clif.c
index 8f9d4566c..4e48d7886 100644
--- a/src/map/clif.c
+++ b/src/map/clif.c
@@ -15293,7 +15293,7 @@ static void clif_parse_FeelSaveOk(int fd, struct map_session_data *sd)
sd->feel_map[i].index = map_id2index(sd->bl.m);
sd->feel_map[i].m = sd->bl.m;
- pc_setglobalreg(sd,script->add_str(pc->sg_info[i].feel_var),sd->feel_map[i].index);
+ pc_setglobalreg(sd,script->add_variable(pc->sg_info[i].feel_var),sd->feel_map[i].index);
#if 0 // Are these really needed? Shouldn't they show up automatically from the feel save packet?
clif_misceffect2(&sd->bl, 0x1b0);
@@ -16856,7 +16856,7 @@ static void clif_quest_update_objective(struct map_session_data *sd, struct ques
qi = quest->db(qd->quest_id);
Assert_retv(qi->objectives_count < MAX_QUEST_OBJECTIVES);
-
+
len = sizeof(struct packet_quest_update_header)
+ MAX_QUEST_OBJECTIVES * sizeof(struct packet_quest_update_hunt); // >= than the actual length
@@ -16869,7 +16869,7 @@ static void clif_quest_update_objective(struct map_session_data *sd, struct ques
for (i = 0; i < qi->objectives_count; i++) {
real_len += sizeof(packet->objectives[i]);
-
+
packet->objectives[i].questID = qd->quest_id;
#if PACKETVER >= 20150513
packet->objectives[i].huntIdent = (qd->quest_id * 1000) + i;
@@ -16899,7 +16899,7 @@ static void clif_quest_notify_objective(struct map_session_data *sd, struct ques
qi = quest->db(qd->quest_id);
Assert_retv(qi->objectives_count < MAX_QUEST_OBJECTIVES);
-
+
len = sizeof(struct packet_quest_hunt_info)
+ MAX_QUEST_OBJECTIVES * sizeof(struct packet_quest_hunt_info_sub); // >= than the actual length
@@ -16911,7 +16911,7 @@ static void clif_quest_notify_objective(struct map_session_data *sd, struct ques
for (i = 0; i < qi->objectives_count; i++) {
real_len += sizeof(packet->info[i]);
-
+
packet->info[i].questID = qd->quest_id;
packet->info[i].mob_id = qi->objectives[i].mob;
packet->info[i].maxCount = qi->objectives[i].count;
@@ -18840,12 +18840,12 @@ static void clif_parse_CashShopBuy(int fd, struct map_session_data *sd)
struct item item_tmp;
int k, get_count;
int ret = 0;
-
+
get_count = qty;
if (!itemdb->isstackable2(data))
get_count = 1;
-
+
ret = pc->paycash(sd, clif->cs.data[tab][j]->price * qty, kafra_pay);// [Ryuuzaki] //changed Kafrapoints calculation. [Normynator]
if (ret < 0) {
ShowError("clif_parse_CashShopBuy: The return from pc->paycash was negative which is not allowed.\n");
@@ -19646,9 +19646,9 @@ static void clif_parse_RouletteOpen(int fd, struct map_session_data *sd)
p.Step = sd->roulette.stage - 1;
p.Idx = (char)sd->roulette.prizeIdx;
p.AdditionItemID = -1; /** TODO **/
- p.BronzePoint = pc_readglobalreg(sd, script->add_str("TmpRouletteBronze"));
- p.GoldPoint = pc_readglobalreg(sd, script->add_str("TmpRouletteGold"));
- p.SilverPoint = pc_readglobalreg(sd, script->add_str("TmpRouletteSilver"));
+ p.BronzePoint = pc_readglobalreg(sd, script->add_variable("TmpRouletteBronze"));
+ p.GoldPoint = pc_readglobalreg(sd, script->add_variable("TmpRouletteGold"));
+ p.SilverPoint = pc_readglobalreg(sd, script->add_variable("TmpRouletteSilver"));
clif->send(&p,sizeof(p), &sd->bl, SELF);
#endif
@@ -19715,21 +19715,21 @@ static void clif_parse_RouletteGenerate(int fd, struct map_session_data *sd)
stage = sd->roulette.stage = 0;
if( stage == 0 ) {
- if( pc_readglobalreg(sd, script->add_str("TmpRouletteBronze")) <= 0 &&
- pc_readglobalreg(sd, script->add_str("TmpRouletteSilver")) < 10 &&
- pc_readglobalreg(sd, script->add_str("TmpRouletteGold")) < 10 )
+ if( pc_readglobalreg(sd, script->add_variable("TmpRouletteBronze")) <= 0 &&
+ pc_readglobalreg(sd, script->add_variable("TmpRouletteSilver")) < 10 &&
+ pc_readglobalreg(sd, script->add_variable("TmpRouletteGold")) < 10 )
result = GENERATE_ROULETTE_NO_ENOUGH_POINT;
}
if( result == GENERATE_ROULETTE_SUCCESS ) {
if( stage == 0 ) {
- if( pc_readglobalreg(sd, script->add_str("TmpRouletteBronze")) > 0 ) {
- pc_setglobalreg(sd, script->add_str("TmpRouletteBronze"), pc_readglobalreg(sd, script->add_str("TmpRouletteBronze")) - 1);
- } else if( pc_readglobalreg(sd, script->add_str("TmpRouletteSilver")) > 9 ) {
- pc_setglobalreg(sd, script->add_str("TmpRouletteSilver"), pc_readglobalreg(sd, script->add_str("TmpRouletteSilver")) - 10);
+ if( pc_readglobalreg(sd, script->add_variable("TmpRouletteBronze")) > 0 ) {
+ pc_setglobalreg(sd, script->add_variable("TmpRouletteBronze"), pc_readglobalreg(sd, script->add_variable("TmpRouletteBronze")) - 1);
+ } else if( pc_readglobalreg(sd, script->add_variable("TmpRouletteSilver")) > 9 ) {
+ pc_setglobalreg(sd, script->add_variable("TmpRouletteSilver"), pc_readglobalreg(sd, script->add_variable("TmpRouletteSilver")) - 10);
stage = sd->roulette.stage = 2;
- } else if( pc_readglobalreg(sd, script->add_str("TmpRouletteGold")) > 9 ) {
- pc_setglobalreg(sd, script->add_str("TmpRouletteGold"), pc_readglobalreg(sd, script->add_str("TmpRouletteGold")) - 10);
+ } else if( pc_readglobalreg(sd, script->add_variable("TmpRouletteGold")) > 9 ) {
+ pc_setglobalreg(sd, script->add_variable("TmpRouletteGold"), pc_readglobalreg(sd, script->add_variable("TmpRouletteGold")) - 10);
stage = sd->roulette.stage = 4;
}
}
@@ -19911,9 +19911,9 @@ static void clif_roulette_generate_ack(struct map_session_data *sd, unsigned cha
p.Step = stage;
p.Idx = prizeIdx;
p.AdditionItemID = bonusItemID;
- p.RemainBronze = pc_readglobalreg(sd, script->add_str("TmpRouletteBronze"));
- p.RemainGold = pc_readglobalreg(sd, script->add_str("TmpRouletteGold"));
- p.RemainSilver = pc_readglobalreg(sd, script->add_str("TmpRouletteSilver"));
+ p.RemainBronze = pc_readglobalreg(sd, script->add_variable("TmpRouletteBronze"));
+ p.RemainGold = pc_readglobalreg(sd, script->add_variable("TmpRouletteGold"));
+ p.RemainSilver = pc_readglobalreg(sd, script->add_variable("TmpRouletteSilver"));
clif->send(&p,sizeof(p), &sd->bl, SELF);
#endif
@@ -20834,7 +20834,7 @@ static void clif_rodex_send_mails_all(int fd, struct map_session_data *sd, int64
nullpo_retv(sd);
mailsSize = VECTOR_LENGTH(sd->rodex.messages);
-
+
if (mail_id > 0)
ARR_FIND(0, VECTOR_LENGTH(sd->rodex.messages), j, (VECTOR_INDEX(sd->rodex.messages, j)).id == mail_id);
@@ -21456,8 +21456,8 @@ static void clif_parse_private_airship_request(int fd, struct map_session_data *
safestrncpy(evname, "private_airship::OnAirShipRequest", EVENT_NAME_LENGTH);
if ((ev = strdb_get(npc->ev_db, evname))) {
- pc->setregstr(sd, script->add_str("@mapname$"), p->mapName);
- pc->setreg(sd, script->add_str("@itemid"), p->ItemID);
+ pc->setregstr(sd, script->add_variable("@mapname$"), p->mapName);
+ pc->setreg(sd, script->add_variable("@itemid"), p->ItemID);
script->run_npc(ev->nd->u.scr.script, ev->pos, sd->bl.id, ev->nd->bl.id);
} else {
ShowError("clif_parse_private_airship_request: event '%s' not found, operation failed.\n", evname);
diff --git a/src/map/duel.c b/src/map/duel.c
index 39e5b5253..c2c24e37b 100644
--- a/src/map/duel.c
+++ b/src/map/duel.c
@@ -47,7 +47,7 @@ static void duel_savetime(struct map_session_data *sd)
time(&clock);
t = localtime(&clock);
- pc_setglobalreg(sd, script->add_str("PC_LAST_DUEL_TIME"), t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min);
+ pc_setglobalreg(sd, script->add_variable("PC_LAST_DUEL_TIME"), t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min);
}
static int duel_checktime(struct map_session_data *sd)
@@ -59,7 +59,7 @@ static int duel_checktime(struct map_session_data *sd)
time(&clock);
t = localtime(&clock);
- diff = t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min - pc_readglobalreg(sd, script->add_str("PC_LAST_DUEL_TIME") );
+ diff = t->tm_mday*24*60 + t->tm_hour*60 + t->tm_min - pc_readglobalreg(sd, script->add_variable("PC_LAST_DUEL_TIME") );
return !(diff >= 0 && diff < battle_config.duel_time_interval);
}
diff --git a/src/map/intif.c b/src/map/intif.c
index 5fafc0913..84fad6c6f 100644
--- a/src/map/intif.c
+++ b/src/map/intif.c
@@ -1324,7 +1324,7 @@ static void intif_parse_Registers(int fd)
safestrncpy(sval, RFIFOP(fd, cursor + 1), min((int)sizeof(sval), len));
cursor += len + 1;
- script->set_reg(NULL,sd,reference_uid(script->add_str(key), index), key, sval, NULL);
+ script->set_reg(NULL,sd,reference_uid(script->add_variable(key), index), key, sval, NULL);
}
/**
* Vessel!
@@ -1346,7 +1346,7 @@ static void intif_parse_Registers(int fd)
ival = RFIFOL(fd, cursor);
cursor += 4;
- script->set_reg(NULL,sd,reference_uid(script->add_str(key), index), key, (const void *)h64BPTRSIZE(ival), NULL);
+ script->set_reg(NULL,sd,reference_uid(script->add_variable(key), index), key, (const void *)h64BPTRSIZE(ival), NULL);
}
}
script->parser_current_file = NULL;/* reset */
diff --git a/src/map/mapreg_sql.c b/src/map/mapreg_sql.c
index 6e8b8f9b0..516be56cb 100644
--- a/src/map/mapreg_sql.c
+++ b/src/map/mapreg_sql.c
@@ -221,7 +221,7 @@ static void script_load_mapreg(void)
SQL->StmtBindColumn(stmt, 2, SQLDT_STRING, &value, sizeof value, NULL, NULL);
while ( SQL_SUCCESS == SQL->StmtNextRow(stmt) ) {
- int s = script->add_str(varname);
+ int s = script->add_variable(varname);
int i = index;
diff --git a/src/map/mob.c b/src/map/mob.c
index 27039490c..220ccc182 100644
--- a/src/map/mob.c
+++ b/src/map/mob.c
@@ -2702,11 +2702,11 @@ static int mob_dead(struct mob_data *md, struct block_list *src, int type)
if (++sd->mission_count >= 100 && (temp = mob->get_random_id(0, 0xE, sd->status.base_level)) != 0) {
pc->addfame(sd, RANKTYPE_TAEKWON, 1);
sd->mission_mobid = temp;
- pc_setglobalreg(sd,script->add_str("TK_MISSION_ID"), temp);
+ pc_setglobalreg(sd,script->add_variable("TK_MISSION_ID"), temp);
sd->mission_count = 0;
clif->mission_info(sd, temp, 0);
}
- pc_setglobalreg(sd,script->add_str("TK_MISSION_COUNT"), sd->mission_count);
+ pc_setglobalreg(sd,script->add_variable("TK_MISSION_COUNT"), sd->mission_count);
}
if( sd->status.party_id )
diff --git a/src/map/npc.c b/src/map/npc.c
index b93b2b6f4..a8bf7d371 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -1762,8 +1762,8 @@ static bool npc_trader_pay(struct npc_data *nd, struct map_session_data *sd, int
snprintf(evname, EVENT_NAME_LENGTH, "%s::OnPayFunds",nd->exname);
if ( (ev = strdb_get(npc->ev_db, evname)) ) {
- pc->setreg(sd,script->add_str("@price"),price);
- pc->setreg(sd,script->add_str("@points"),points);
+ pc->setreg(sd,script->add_variable("@price"),price);
+ pc->setreg(sd,script->add_variable("@points"),points);
script->run_npc(ev->nd->u.scr.script, ev->pos, sd->bl.id, ev->nd->bl.id);
} else
ShowError("npc_trader_pay: '%s' event '%s' not found, operation failed\n",nd->exname,evname);
diff --git a/src/map/pc.c b/src/map/pc.c
index 0aad00a56..be28f8dad 100644
--- a/src/map/pc.c
+++ b/src/map/pc.c
@@ -1459,7 +1459,7 @@ static int pc_set_hate_mob(struct map_session_data *sd, int pos, struct block_li
return 0; //Wrong size
}
sd->hate_mob[pos] = class_;
- pc_setglobalreg(sd,script->add_str(pc->sg_info[pos].hate_var),class_+1);
+ pc_setglobalreg(sd,script->add_variable(pc->sg_info[pos].hate_var),class_+1);
clif->hate_info(sd, pos, class_, 1);
return 1;
}
@@ -1473,27 +1473,28 @@ static int pc_reg_received(struct map_session_data *sd)
nullpo_ret(sd);
sd->vars_ok = true;
- sd->change_level_2nd = pc_readglobalreg(sd,script->add_str("jobchange_level"));
- sd->change_level_3rd = pc_readglobalreg(sd,script->add_str("jobchange_level_3rd"));
- sd->die_counter = pc_readglobalreg(sd,script->add_str("PC_DIE_COUNTER"));
+
+ sd->change_level_2nd = pc_readglobalreg(sd,script->add_variable("jobchange_level"));
+ sd->change_level_3rd = pc_readglobalreg(sd,script->add_variable("jobchange_level_3rd"));
+ sd->die_counter = pc_readglobalreg(sd,script->add_variable("PC_DIE_COUNTER"));
// Cash shop
- sd->cashPoints = pc_readaccountreg(sd,script->add_str("#CASHPOINTS"));
- sd->kafraPoints = pc_readaccountreg(sd,script->add_str("#KAFRAPOINTS"));
+ sd->cashPoints = pc_readaccountreg(sd,script->add_variable("#CASHPOINTS"));
+ sd->kafraPoints = pc_readaccountreg(sd,script->add_variable("#KAFRAPOINTS"));
// Cooking Exp
- sd->cook_mastery = pc_readglobalreg(sd,script->add_str("COOK_MASTERY"));
+ sd->cook_mastery = pc_readglobalreg(sd,script->add_variable("COOK_MASTERY"));
if ((sd->job & MAPID_BASEMASK) == MAPID_TAEKWON) {
// Better check for class rather than skill to prevent "skill resets" from unsetting this
- sd->mission_mobid = pc_readglobalreg(sd,script->add_str("TK_MISSION_ID"));
- sd->mission_count = pc_readglobalreg(sd,script->add_str("TK_MISSION_COUNT"));
+ sd->mission_mobid = pc_readglobalreg(sd,script->add_variable("TK_MISSION_ID"));
+ sd->mission_count = pc_readglobalreg(sd,script->add_variable("TK_MISSION_COUNT"));
}
//SG map and mob read [Komurka]
for (i = 0; i < MAX_PC_FEELHATE; i++) {
//for now - someone need to make reading from txt/sql
- int j = pc_readglobalreg(sd,script->add_str(pc->sg_info[i].feel_var));
+ int j = pc_readglobalreg(sd,script->add_variable(pc->sg_info[i].feel_var));
if (j != 0) {
sd->feel_map[i].index = j;
sd->feel_map[i].m = map->mapindex2mapid(j);
@@ -1501,24 +1502,24 @@ static int pc_reg_received(struct map_session_data *sd)
sd->feel_map[i].index = 0;
sd->feel_map[i].m = -1;
}
- sd->hate_mob[i] = pc_readglobalreg(sd,script->add_str(pc->sg_info[i].hate_var))-1;
+ sd->hate_mob[i] = pc_readglobalreg(sd,script->add_variable(pc->sg_info[i].hate_var))-1;
}
if ((i = pc->checkskill(sd,RG_PLAGIARISM)) > 0) {
- sd->cloneskill_id = pc_readglobalreg(sd,script->add_str("CLONE_SKILL"));
+ sd->cloneskill_id = pc_readglobalreg(sd,script->add_variable("CLONE_SKILL"));
if (sd->cloneskill_id > 0 && (idx = skill->get_index(sd->cloneskill_id)) > 0) {
sd->status.skill[idx].id = sd->cloneskill_id;
- sd->status.skill[idx].lv = pc_readglobalreg(sd,script->add_str("CLONE_SKILL_LV"));
+ sd->status.skill[idx].lv = pc_readglobalreg(sd,script->add_variable("CLONE_SKILL_LV"));
if (sd->status.skill[idx].lv > i)
sd->status.skill[idx].lv = i;
sd->status.skill[idx].flag = SKILL_FLAG_PLAGIARIZED;
}
}
if ((i = pc->checkskill(sd,SC_REPRODUCE)) > 0) {
- sd->reproduceskill_id = pc_readglobalreg(sd,script->add_str("REPRODUCE_SKILL"));
+ sd->reproduceskill_id = pc_readglobalreg(sd,script->add_variable("REPRODUCE_SKILL"));
if( sd->reproduceskill_id > 0 && (idx = skill->get_index(sd->reproduceskill_id)) > 0) {
sd->status.skill[idx].id = sd->reproduceskill_id;
- sd->status.skill[idx].lv = pc_readglobalreg(sd,script->add_str("REPRODUCE_SKILL_LV"));
+ sd->status.skill[idx].lv = pc_readglobalreg(sd,script->add_variable("REPRODUCE_SKILL_LV"));
if( i < sd->status.skill[idx].lv)
sd->status.skill[idx].lv = i;
sd->status.skill[idx].flag = SKILL_FLAG_PLAGIARIZED;
@@ -1964,7 +1965,7 @@ static int pc_calc_skilltree_normalize_job(struct map_session_data *sd)
}
- pc_setglobalreg(sd, script->add_str("jobchange_level"), sd->change_level_2nd);
+ pc_setglobalreg(sd, script->add_variable("jobchange_level"), sd->change_level_2nd);
}
if (skill_point < novice_skills + (sd->change_level_2nd - 1)) {
@@ -1977,7 +1978,7 @@ static int pc_calc_skilltree_normalize_job(struct map_session_data *sd)
- (sd->status.job_level - 1)
- (sd->change_level_2nd - 1)
- novice_skills;
- pc_setglobalreg(sd, script->add_str("jobchange_level_3rd"), sd->change_level_3rd);
+ pc_setglobalreg(sd, script->add_variable("jobchange_level_3rd"), sd->change_level_3rd);
}
if (skill_point < novice_skills + (sd->change_level_2nd - 1) + (sd->change_level_3rd - 1)) {
@@ -4523,7 +4524,7 @@ static int pc_payzeny(struct map_session_data *sd, int zeny, enum e_log_pick_typ
*
* @param price Price of the item.
* @param points Provided kafra points.
- *
+ *
* @return points Leftover kafra points.
*/
//Changed Kafrapoints calculation. [Normynator]
@@ -4555,15 +4556,15 @@ static int pc_paycash(struct map_session_data *sd, int price, int points)
return -1;
}
- pc_setaccountreg(sd, script->add_str("#CASHPOINTS"), sd->cashPoints - cash);
- pc_setaccountreg(sd, script->add_str("#KAFRAPOINTS"), sd->kafraPoints - mempoints);
+ pc_setaccountreg(sd, script->add_variable("#CASHPOINTS"), sd->cashPoints - cash);
+ pc_setaccountreg(sd, script->add_variable("#KAFRAPOINTS"), sd->kafraPoints - mempoints);
if (battle_config.cashshop_show_points) {
char output[128];
sprintf(output, msg_sd(sd,504), points, cash, sd->kafraPoints, sd->cashPoints);
clif_disp_onlyself(sd, output);
}
-
+
return points;
}
@@ -4582,7 +4583,7 @@ static int pc_getcash(struct map_session_data *sd, int cash, int points)
cash = MAX_ZENY-sd->cashPoints;
}
- pc_setaccountreg(sd, script->add_str("#CASHPOINTS"), sd->cashPoints+cash);
+ pc_setaccountreg(sd, script->add_variable("#CASHPOINTS"), sd->cashPoints+cash);
if( battle_config.cashshop_show_points )
{
@@ -4605,7 +4606,7 @@ static int pc_getcash(struct map_session_data *sd, int cash, int points)
points = MAX_ZENY-sd->kafraPoints;
}
- pc_setaccountreg(sd, script->add_str("#KAFRAPOINTS"), sd->kafraPoints+points);
+ pc_setaccountreg(sd, script->add_variable("#KAFRAPOINTS"), sd->kafraPoints+points);
if( battle_config.cashshop_show_points )
{
@@ -5789,7 +5790,7 @@ static int pc_setpos(struct map_session_data *sd, unsigned short map_index, int
for (i = 0; i < VECTOR_LENGTH(sd->script_queues); i++) {
struct script_queue *queue = script->queue(VECTOR_INDEX(sd->script_queues, i));
if (queue && queue->event_mapchange[0] != '\0') {
- pc->setregstr(sd, script->add_str("@Queue_Destination_Map$"), map->list[m].name);
+ pc->setregstr(sd, script->add_variable("@Queue_Destination_Map$"), map->list[m].name);
npc->event(sd, queue->event_mapchange, 0);
}
}
@@ -7220,7 +7221,7 @@ static uint64 pc_thisjobexp(const struct map_session_data *sd)
const struct class_exp_group *exp_group = NULL;
nullpo_ret(sd);
-
+
if (sd->status.job_level > pc->maxjoblv(sd) || sd->status.job_level <= 1)
return 0;
@@ -7696,7 +7697,7 @@ static int pc_resetstate(struct map_session_data *sd)
if( sd->mission_mobid ) { //bugreport:2200
sd->mission_mobid = 0;
sd->mission_count = 0;
- pc_setglobalreg(sd,script->add_str("TK_MISSION_ID"), 0);
+ pc_setglobalreg(sd,script->add_variable("TK_MISSION_ID"), 0);
}
status_calc_pc(sd,SCO_NONE);
@@ -7856,7 +7857,7 @@ static int pc_resetfeel(struct map_session_data *sd)
{
sd->feel_map[i].m = -1;
sd->feel_map[i].index = 0;
- pc_setglobalreg(sd,script->add_str(pc->sg_info[i].feel_var),0);
+ pc_setglobalreg(sd,script->add_variable(pc->sg_info[i].feel_var),0);
}
return 0;
@@ -7869,7 +7870,7 @@ static int pc_resethate(struct map_session_data *sd)
for (i = 0; i < MAX_PC_FEELHATE; i++) {
sd->hate_mob[i] = -1;
- pc_setglobalreg(sd,script->add_str(pc->sg_info[i].hate_var),0);
+ pc_setglobalreg(sd,script->add_variable(pc->sg_info[i].hate_var),0);
}
return 0;
}
@@ -8059,7 +8060,7 @@ static int pc_dead(struct map_session_data *sd, struct block_list *src)
if (sd->npc_id && sd->st && sd->st->state != RUN)
npc->event_dequeue(sd);
- pc_setglobalreg(sd,script->add_str("PC_DIE_COUNTER"),sd->die_counter+1);
+ pc_setglobalreg(sd,script->add_variable("PC_DIE_COUNTER"),sd->die_counter+1);
pc->setparam(sd, SP_KILLERRID, src?src->id:0);
if( sd->bg_id ) {/* TODO: purge when bgqueue is deemed ok */
@@ -8920,11 +8921,11 @@ static int pc_jobchange(struct map_session_data *sd, int class, int upper)
if ((job & JOBL_2) != 0 && (sd->job & JOBL_2) == 0 && (job & MAPID_UPPERMASK) != MAPID_SUPER_NOVICE) {
// changing from 1st to 2nd job
sd->change_level_2nd = sd->status.job_level;
- pc_setglobalreg(sd, script->add_str("jobchange_level"), sd->change_level_2nd);
+ pc_setglobalreg(sd, script->add_variable("jobchange_level"), sd->change_level_2nd);
} else if((job & JOBL_THIRD) != 0 && (sd->job & JOBL_THIRD) == 0) {
// changing from 2nd to 3rd job
sd->change_level_3rd = sd->status.job_level;
- pc_setglobalreg(sd, script->add_str("jobchange_level_3rd"), sd->change_level_3rd);
+ pc_setglobalreg(sd, script->add_variable("jobchange_level_3rd"), sd->change_level_3rd);
}
if(sd->cloneskill_id) {
@@ -8936,8 +8937,8 @@ static int pc_jobchange(struct map_session_data *sd, int class, int upper)
clif->deleteskill(sd,sd->cloneskill_id);
}
sd->cloneskill_id = 0;
- pc_setglobalreg(sd, script->add_str("CLONE_SKILL"), 0);
- pc_setglobalreg(sd, script->add_str("CLONE_SKILL_LV"), 0);
+ pc_setglobalreg(sd, script->add_variable("CLONE_SKILL"), 0);
+ pc_setglobalreg(sd, script->add_variable("CLONE_SKILL_LV"), 0);
}
if(sd->reproduceskill_id) {
@@ -8949,8 +8950,8 @@ static int pc_jobchange(struct map_session_data *sd, int class, int upper)
clif->deleteskill(sd,sd->reproduceskill_id);
}
sd->reproduceskill_id = 0;
- pc_setglobalreg(sd, script->add_str("REPRODUCE_SKILL"),0);
- pc_setglobalreg(sd, script->add_str("REPRODUCE_SKILL_LV"),0);
+ pc_setglobalreg(sd, script->add_variable("REPRODUCE_SKILL"),0);
+ pc_setglobalreg(sd, script->add_variable("REPRODUCE_SKILL_LV"),0);
}
if ((job & MAPID_UPPERMASK) != (sd->job & MAPID_UPPERMASK)) { //Things to remove when changing class tree.
diff --git a/src/map/script.c b/src/map/script.c
index 477d2ad98..e6c4ef1d1 100644
--- a/src/map/script.c
+++ b/src/map/script.c
@@ -613,6 +613,18 @@ static int script_add_str(const char *p)
return script->str_num++;
}
+static int script_add_variable(const char *varname)
+{
+ int key = script->search_str(varname);
+
+ if (key < 0) {
+ key = script->add_str(varname);
+ script->str_data[key].type = C_NAME;
+ }
+
+ return key;
+}
+
/**
* Appends 1 byte to the script buffer.
*
@@ -1366,6 +1378,11 @@ static const char *parse_simpleexpr_name(const char *p)
disp_error_message("parse_simpleexpr: unmatched ']'", p);
++p;
script->addc(C_FUNC);
+ } else if (script->str_data[l].type == C_INT) {
+ script->addc(C_NAME);
+ script->addb(l);
+ script->addb(l >> 8);
+ script->addb(l >> 16);
} else {
script->addl(l);
}
@@ -2886,8 +2903,7 @@ static struct script_data *get_val(struct script_state *st, struct script_data *
return data;
}
- //##TODO use reference_tovariable(data) when it's confirmed that it works [FlavioJS]
- if (!reference_toconstant(data) && not_server_variable(prefix) && reference_getref(data) == NULL) {
+ if (((reference_tovariable(data) && not_server_variable(prefix)) || reference_toparam(data)) && reference_getref(data) == NULL) {
sd = script->rid2sd(st);
if (sd == NULL) {// needs player attached
if (postfix == '$') {// string variable
@@ -3032,6 +3048,10 @@ static const void *get_val2(struct script_state *st, int64 uid, struct reg_db *r
script->get_val(st, data);
if (data->type == C_INT) // u.num is int32 because it comes from script->get_val
return (const void *)h64BPTRSIZE((int32)data->u.num);
+ else if (data_isreference(data) && reference_toconstant(data))
+ return (const void *)h64BPTRSIZE((int32)reference_getconstant(data));
+ else if (data_isreference(data) && reference_toparam(data))
+ return (const void *)h64BPTRSIZE((int32)reference_getparamtype(data));
else
return (const void *)h64BPTRSIZE(data->u.str);
}
@@ -3460,6 +3480,19 @@ static int set_reg(struct script_state *st, struct map_session_data *sd, int64 n
nullpo_ret(name);
prefix = name[0];
+ if (script->str_data[script_getvarid(num)].type != C_NAME) {
+ ShowError("script:set_reg: not a variable! '%s'\n", name);
+
+ // to avoid this don't do script->add_str(") without setting its type.
+ // either use script->add_variable() or manually set the type
+
+ if (st) {
+ script->reportsrc(st);
+ st->state = END;
+ }
+ return 0;
+ }
+
if (strlen(name) > SCRIPT_VARNAME_LENGTH) {
ShowError("script:set_reg: variable name too long. '%s'\n", name);
if (st) {
@@ -3579,12 +3612,26 @@ static int set_reg(struct script_state *st, struct map_session_data *sd, int64 n
static int set_var(struct map_session_data *sd, char *name, void *val)
{
- return script->set_reg(NULL, sd, reference_uid(script->add_str(name),0), name, val, NULL);
+ int key = script->add_variable(name);
+
+ if (script->str_data[key].type != C_NAME) {
+ ShowError("script:setd_sub: `%s` is already used by something that is not a variable.\n", name);
+ return -1;
+ }
+
+ return script->set_reg(NULL, sd, reference_uid(key, 0), name, val, NULL);
}
static void setd_sub(struct script_state *st, struct map_session_data *sd, const char *varname, int elem, const void *value, struct reg_db *ref)
{
- script->set_reg(st, sd, reference_uid(script->add_str(varname),elem), varname, value, ref);
+ int key = script->add_variable(varname);
+
+ if (script->str_data[key].type != C_NAME) {
+ ShowError("script:setd_sub: `%s` is already used by something that is not a variable.\n", varname);
+ return;
+ }
+
+ script->set_reg(st, sd, reference_uid(key, elem), varname, value, ref);
}
/// Converts the data to a string
@@ -4119,10 +4166,10 @@ static void op_2str(struct script_state *st, int op, const char *s1, const char
int i;
for (i = 0; i < offsetcount; i++) {
libpcre->get_substring(s1, offsets, offsetcount, i, &pcre_match);
- mapreg->setregstr(reference_uid(script->add_str("$@regexmatch$"), i), pcre_match);
+ mapreg->setregstr(reference_uid(script->add_variable("$@regexmatch$"), i), pcre_match);
libpcre->free_substring(pcre_match);
}
- mapreg->setreg(script->add_str("$@regexmatchcount"), i);
+ mapreg->setreg(script->add_variable("$@regexmatchcount"), i);
a = offsetcount;
} else { // C_RE_NE
a = (offsetcount == 0);
@@ -4905,7 +4952,12 @@ static void script_cleararray_pc(struct map_session_data *sd, const char *varnam
unsigned int i, *list = NULL, size = 0;
int key;
- key = script->add_str(varname);
+ key = script->add_variable(varname);
+
+ if (script->str_data[key].type != C_NAME) {
+ ShowError("script:cleararray_pc: `%s` is already used by something that is not a variable.\n", varname);
+ return;
+ }
if( !(src = script->array_src(NULL,sd,varname,NULL) ) )
return;
@@ -4935,7 +4987,12 @@ static void script_setarray_pc(struct map_session_data *sd, const char *varname,
return;
}
- key = ( refcache && refcache[0] ) ? refcache[0] : script->add_str(varname);
+ key = ( refcache && refcache[0] ) ? refcache[0] : script->add_variable(varname);
+
+ if (script->str_data[key].type != C_NAME) {
+ ShowError("script:setarray_pc: `%s` is already used by something that is not a variable.\n", varname);
+ return;
+ }
script->set_reg(NULL,sd,reference_uid(key, idx),varname,value,NULL);
@@ -6162,7 +6219,7 @@ static BUILDIN(menu)
st->state = END;
return false;
}
- pc->setreg(sd, script->add_str("@menu"), menu);
+ pc->setreg(sd, script->add_variable("@menu"), menu);
st->pos = script_getnum(st, i + 1);
st->state = GOTO;
}
@@ -6235,7 +6292,7 @@ static BUILDIN(select)
if( sd->npc_menu <= 0 )
break;// entry found
}
- pc->setreg(sd, script->add_str("@menu"), menu);
+ pc->setreg(sd, script->add_variable("@menu"), menu);
script_pushint(st, menu);
st->state = RUN;
}
@@ -6302,7 +6359,7 @@ static BUILDIN(prompt)
else if( sd->npc_menu == 0xff )
{// Cancel was pressed
sd->state.menu_or_input = 0;
- pc->setreg(sd, script->add_str("@menu"), 0xff);
+ pc->setreg(sd, script->add_variable("@menu"), 0xff);
script_pushint(st, 0xff);
st->state = RUN;
}
@@ -6318,7 +6375,7 @@ static BUILDIN(prompt)
if( sd->npc_menu <= 0 )
break;// entry found
}
- pc->setreg(sd, script->add_str("@menu"), menu);
+ pc->setreg(sd, script->add_variable("@menu"), menu);
script_pushint(st, menu);
st->state = RUN;
}
@@ -8857,19 +8914,19 @@ static BUILDIN(getpartymember)
if(p->party.member[i].account_id) {
switch (type) {
case 2:
- mapreg->setreg(reference_uid(script->add_str("$@partymemberaid"), j),p->party.member[i].account_id);
+ mapreg->setreg(reference_uid(script->add_variable("$@partymemberaid"), j),p->party.member[i].account_id);
break;
case 1:
- mapreg->setreg(reference_uid(script->add_str("$@partymembercid"), j),p->party.member[i].char_id);
+ mapreg->setreg(reference_uid(script->add_variable("$@partymembercid"), j),p->party.member[i].char_id);
break;
default:
- mapreg->setregstr(reference_uid(script->add_str("$@partymembername$"), j),p->party.member[i].name);
+ mapreg->setregstr(reference_uid(script->add_variable("$@partymembername$"), j),p->party.member[i].name);
}
j++;
}
}
}
- mapreg->setreg(script->add_str("$@partymembercount"),j);
+ mapreg->setreg(script->add_variable("$@partymembercount"),j);
return true;
}
@@ -8999,20 +9056,20 @@ static BUILDIN(getguildmember)
if ( g->member[i].account_id ) {
switch (type) {
case 2:
- mapreg->setreg(reference_uid(script->add_str("$@guildmemberaid"), j),g->member[i].account_id);
+ mapreg->setreg(reference_uid(script->add_variable("$@guildmemberaid"), j),g->member[i].account_id);
break;
case 1:
- mapreg->setreg(reference_uid(script->add_str("$@guildmembercid"), j), g->member[i].char_id);
+ mapreg->setreg(reference_uid(script->add_variable("$@guildmembercid"), j), g->member[i].char_id);
break;
default:
- mapreg->setregstr(reference_uid(script->add_str("$@guildmembername$"), j), g->member[i].name);
+ mapreg->setregstr(reference_uid(script->add_variable("$@guildmembername$"), j), g->member[i].name);
break;
}
j++;
}
}
}
- mapreg->setreg(script->add_str("$@guildmembercount"), j);
+ mapreg->setreg(script->add_variable("$@guildmembercount"), j);
return true;
}
@@ -10917,13 +10974,13 @@ static BUILDIN(getmobdrops)
if( itemdb->exists(monster->dropitem[i].nameid) == NULL )
continue;
- mapreg->setreg(reference_uid(script->add_str("$@MobDrop_item"), j), monster->dropitem[i].nameid);
- mapreg->setreg(reference_uid(script->add_str("$@MobDrop_rate"), j), monster->dropitem[i].p);
+ mapreg->setreg(reference_uid(script->add_variable("$@MobDrop_item"), j), monster->dropitem[i].nameid);
+ mapreg->setreg(reference_uid(script->add_variable("$@MobDrop_rate"), j), monster->dropitem[i].p);
j++;
}
- mapreg->setreg(script->add_str("$@MobDrop_count"), j);
+ mapreg->setreg(script->add_variable("$@MobDrop_count"), j);
script_pushint(st, 1);
return true;
@@ -12863,7 +12920,7 @@ static BUILDIN(getwaitingroomstate)
for (i = 0; i < cd->users; i++) {
struct map_session_data *sd = cd->usersd[i];
nullpo_retr(false, sd);
- mapreg->setreg(reference_uid(script->add_str("$@chatmembers"), i), sd->bl.id);
+ mapreg->setreg(reference_uid(script->add_variable("$@chatmembers"), i), sd->bl.id);
}
script_pushint(st, cd->users);
break;
@@ -12933,7 +12990,7 @@ static BUILDIN(warpwaitingpc)
pc->payzeny(sd, cd->zeny, LOG_TYPE_NPC, NULL);
}
- mapreg->setreg(reference_uid(script->add_str("$@warpwaitingpc"), i), sd->bl.id);
+ mapreg->setreg(reference_uid(script->add_variable("$@warpwaitingpc"), i), sd->bl.id);
if( strcmp(map_name,"Random") == 0 )
pc->randomwarp(sd,CLR_TELEPORT);
@@ -12942,7 +12999,7 @@ static BUILDIN(warpwaitingpc)
else
pc->setpos(sd, script->mapindexname2id(st,map_name), x, y, CLR_OUTSIGHT);
}
- mapreg->setreg(script->add_str("$@warpwaitingpcnum"), i);
+ mapreg->setreg(script->add_variable("$@warpwaitingpcnum"), i);
return true;
}
@@ -14818,34 +14875,34 @@ static BUILDIN(getinventorylist)
for(i=0;i<MAX_INVENTORY;i++) {
if(sd->status.inventory[i].nameid > 0 && sd->status.inventory[i].amount > 0) {
- pc->setreg(sd,reference_uid(script->add_str("@inventorylist_id"), j),sd->status.inventory[i].nameid);
- pc->setreg(sd,reference_uid(script->add_str("@inventorylist_amount"), j),sd->status.inventory[i].amount);
+ pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_id"), j),sd->status.inventory[i].nameid);
+ pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_amount"), j),sd->status.inventory[i].amount);
if(sd->status.inventory[i].equip) {
- pc->setreg(sd,reference_uid(script->add_str("@inventorylist_equip"), j),pc->equippoint(sd,i));
+ pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_equip"), j),pc->equippoint(sd,i));
} else {
- pc->setreg(sd,reference_uid(script->add_str("@inventorylist_equip"), j),0);
+ pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_equip"), j),0);
}
- pc->setreg(sd,reference_uid(script->add_str("@inventorylist_refine"), j),sd->status.inventory[i].refine);
- pc->setreg(sd,reference_uid(script->add_str("@inventorylist_identify"), j),sd->status.inventory[i].identify);
- pc->setreg(sd,reference_uid(script->add_str("@inventorylist_attribute"), j),sd->status.inventory[i].attribute);
+ pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_refine"), j),sd->status.inventory[i].refine);
+ pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_identify"), j),sd->status.inventory[i].identify);
+ pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_attribute"), j),sd->status.inventory[i].attribute);
for (k = 0; k < MAX_SLOTS; k++) {
sprintf(card_var, "@inventorylist_card%d",k+1);
- pc->setreg(sd,reference_uid(script->add_str(card_var), j),sd->status.inventory[i].card[k]);
+ pc->setreg(sd,reference_uid(script->add_variable(card_var), j),sd->status.inventory[i].card[k]);
}
for (k = 0; k < MAX_ITEM_OPTIONS; k++) {
sprintf(card_var, "@inventorylist_opt_id%d", k + 1);
- pc->setreg(sd, reference_uid(script->add_str(card_var), j), sd->status.inventory[i].option[k].index);
+ pc->setreg(sd, reference_uid(script->add_variable(card_var), j), sd->status.inventory[i].option[k].index);
sprintf(card_var, "@inventorylist_opt_val%d", k + 1);
- pc->setreg(sd, reference_uid(script->add_str(card_var), j), sd->status.inventory[i].option[k].value);
+ pc->setreg(sd, reference_uid(script->add_variable(card_var), j), sd->status.inventory[i].option[k].value);
sprintf(card_var, "@inventorylist_opt_param%d", k + 1);
- pc->setreg(sd, reference_uid(script->add_str(card_var), j), sd->status.inventory[i].option[k].param);
+ pc->setreg(sd, reference_uid(script->add_variable(card_var), j), sd->status.inventory[i].option[k].param);
}
- pc->setreg(sd,reference_uid(script->add_str("@inventorylist_expire"), j),sd->status.inventory[i].expire_time);
- pc->setreg(sd,reference_uid(script->add_str("@inventorylist_bound"), j),sd->status.inventory[i].bound);
+ pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_expire"), j),sd->status.inventory[i].expire_time);
+ pc->setreg(sd,reference_uid(script->add_variable("@inventorylist_bound"), j),sd->status.inventory[i].bound);
j++;
}
}
- pc->setreg(sd,script->add_str("@inventorylist_count"),j);
+ pc->setreg(sd,script->add_variable("@inventorylist_count"),j);
return true;
}
@@ -14859,30 +14916,30 @@ static BUILDIN(getcartinventorylist)
for(i=0;i<MAX_CART;i++) {
if(sd->status.cart[i].nameid > 0 && sd->status.cart[i].amount > 0) {
- pc->setreg(sd,reference_uid(script->add_str("@cartinventorylist_id"), j),sd->status.cart[i].nameid);
- pc->setreg(sd,reference_uid(script->add_str("@cartinventorylist_amount"), j),sd->status.cart[i].amount);
- pc->setreg(sd,reference_uid(script->add_str("@cartinventorylist_equip"), j),sd->status.cart[i].equip);
- pc->setreg(sd,reference_uid(script->add_str("@cartinventorylist_refine"), j),sd->status.cart[i].refine);
- pc->setreg(sd,reference_uid(script->add_str("@cartinventorylist_identify"), j),sd->status.cart[i].identify);
- pc->setreg(sd,reference_uid(script->add_str("@cartinventorylist_attribute"), j),sd->status.cart[i].attribute);
+ pc->setreg(sd,reference_uid(script->add_variable("@cartinventorylist_id"), j),sd->status.cart[i].nameid);
+ pc->setreg(sd,reference_uid(script->add_variable("@cartinventorylist_amount"), j),sd->status.cart[i].amount);
+ pc->setreg(sd,reference_uid(script->add_variable("@cartinventorylist_equip"), j),sd->status.cart[i].equip);
+ pc->setreg(sd,reference_uid(script->add_variable("@cartinventorylist_refine"), j),sd->status.cart[i].refine);
+ pc->setreg(sd,reference_uid(script->add_variable("@cartinventorylist_identify"), j),sd->status.cart[i].identify);
+ pc->setreg(sd,reference_uid(script->add_variable("@cartinventorylist_attribute"), j),sd->status.cart[i].attribute);
for (k = 0; k < MAX_SLOTS; k++) {
sprintf(card_var, "@cartinventorylist_card%d",k+1);
- pc->setreg(sd,reference_uid(script->add_str(card_var), j),sd->status.cart[i].card[k]);
+ pc->setreg(sd,reference_uid(script->add_variable(card_var), j),sd->status.cart[i].card[k]);
}
for (k = 0; k < MAX_ITEM_OPTIONS; k++) {
sprintf(card_var, "@cartinventorylist_opt_id%d", k + 1);
- pc->setreg(sd, reference_uid(script->add_str(card_var), j), sd->status.cart[i].option[k].index);
+ pc->setreg(sd, reference_uid(script->add_variable(card_var), j), sd->status.cart[i].option[k].index);
sprintf(card_var, "@cartinventorylist_opt_val%d", k + 1);
- pc->setreg(sd, reference_uid(script->add_str(card_var), j), sd->status.cart[i].option[k].value);
+ pc->setreg(sd, reference_uid(script->add_variable(card_var), j), sd->status.cart[i].option[k].value);
sprintf(card_var, "@cartinventorylist_opt_param%d", k + 1);
- pc->setreg(sd, reference_uid(script->add_str(card_var), j), sd->status.cart[i].option[k].param);
+ pc->setreg(sd, reference_uid(script->add_variable(card_var), j), sd->status.cart[i].option[k].param);
}
- pc->setreg(sd,reference_uid(script->add_str("@cartinventorylist_expire"), j),sd->status.cart[i].expire_time);
- pc->setreg(sd,reference_uid(script->add_str("@cartinventorylist_bound"), j),sd->status.cart[i].bound);
+ pc->setreg(sd,reference_uid(script->add_variable("@cartinventorylist_expire"), j),sd->status.cart[i].expire_time);
+ pc->setreg(sd,reference_uid(script->add_variable("@cartinventorylist_bound"), j),sd->status.cart[i].bound);
j++;
}
}
- pc->setreg(sd,script->add_str("@cartinventorylist_count"),j);
+ pc->setreg(sd,script->add_variable("@cartinventorylist_count"),j);
return true;
}
@@ -14894,13 +14951,13 @@ static BUILDIN(getskilllist)
return true;
for (i = 0; i < MAX_SKILL_DB; i++) {
if(sd->status.skill[i].id > 0 && sd->status.skill[i].lv > 0) {
- pc->setreg(sd,reference_uid(script->add_str("@skilllist_id"), j),sd->status.skill[i].id);
- pc->setreg(sd,reference_uid(script->add_str("@skilllist_lv"), j),sd->status.skill[i].lv);
- pc->setreg(sd,reference_uid(script->add_str("@skilllist_flag"), j),sd->status.skill[i].flag);
+ pc->setreg(sd,reference_uid(script->add_variable("@skilllist_id"), j),sd->status.skill[i].id);
+ pc->setreg(sd,reference_uid(script->add_variable("@skilllist_lv"), j),sd->status.skill[i].lv);
+ pc->setreg(sd,reference_uid(script->add_variable("@skilllist_flag"), j),sd->status.skill[i].flag);
j++;
}
}
- pc->setreg(sd,script->add_str("@skilllist_count"),j);
+ pc->setreg(sd,script->add_variable("@skilllist_count"),j);
return true;
}
@@ -17807,12 +17864,9 @@ static BUILDIN(getd)
if (sscanf(buffer, "%99[^[][%d]", varname, &elem) < 2)
elem = 0;
- id = script->search_str(varname);
+ id = script->add_variable(varname);
- if (id < 0 || script->str_data[id].type == C_NOP) {
- id = script->add_str(varname);
- script->str_data[id].type = C_NAME;
- } else if (script->str_data[id].type != C_NAME) {
+ if (script->str_data[id].type != C_NAME) {
ShowError("script:getd: `%s` is already used by something that is not a variable.\n", varname);
st->state = END;
return false;
@@ -21413,12 +21467,12 @@ static BUILDIN(waitingroom2bg)
for (i = 0; i < n && i < MAX_BG_MEMBERS; i++) {
struct map_session_data *sd = cd->usersd[i];
if (sd != NULL && bg->team_join(bg_id, sd))
- mapreg->setreg(reference_uid(script->add_str("$@arenamembers"), i), sd->bl.id);
+ mapreg->setreg(reference_uid(script->add_variable("$@arenamembers"), i), sd->bl.id);
else
- mapreg->setreg(reference_uid(script->add_str("$@arenamembers"), i), 0);
+ mapreg->setreg(reference_uid(script->add_variable("$@arenamembers"), i), 0);
}
- mapreg->setreg(script->add_str("$@arenamembersnum"), i);
+ mapreg->setreg(script->add_variable("$@arenamembersnum"), i);
script_pushint(st,bg_id);
return true;
}
@@ -23630,7 +23684,7 @@ static BUILDIN(countbound)
(!type && sd->status.inventory[i].bound > 0) ||
(type && sd->status.inventory[i].bound == type)
)) {
- pc->setreg(sd,reference_uid(script->add_str("@bound_items"), k),sd->status.inventory[i].nameid);
+ pc->setreg(sd,reference_uid(script->add_variable("@bound_items"), k),sd->status.inventory[i].nameid);
k++;
j += sd->status.inventory[i].amount;
}
@@ -26051,6 +26105,7 @@ void script_defaults(void)
script->setarray_pc = script_setarray_pc;
script->config_read = script_config_read;
script->add_str = script_add_str;
+ script->add_variable = script_add_variable;
script->get_str = script_get_str;
script->search_str = script_search_str;
script->setd_sub = setd_sub;
diff --git a/src/map/script.h b/src/map/script.h
index 9a8425ed2..9c72b793c 100644
--- a/src/map/script.h
+++ b/src/map/script.h
@@ -143,7 +143,6 @@ struct item_data;
/// Returns if this a reference to a param
#define reference_toparam(data) ( script->str_data[reference_getid(data)].type == C_PARAM )
/// Returns if this a reference to a variable
-//##TODO confirm it's C_NAME [FlavioJS]
#define reference_tovariable(data) ( script->str_data[reference_getid(data)].type == C_NAME )
/// Returns the unique id of the reference (id and index)
#define reference_getuid(data) ( (data)->u.num )
@@ -829,6 +828,7 @@ struct script_interface {
void (*setarray_pc) (struct map_session_data* sd, const char* varname, uint32 idx, void* value, int* refcache);
bool (*config_read) (const char *filename, bool imported);
int (*add_str) (const char* p);
+ int (*add_variable) (const char *varname);
const char* (*get_str) (int id);
int (*search_str) (const char* p);
void (*setd_sub) (struct script_state *st, struct map_session_data *sd, const char *varname, int elem, const void *value, struct reg_db *ref);
diff --git a/src/map/skill.c b/src/map/skill.c
index 7d47cfcb6..c5579c2f6 100644
--- a/src/map/skill.c
+++ b/src/map/skill.c
@@ -3218,8 +3218,8 @@ static int skill_attack(int attack_type, struct block_list *src, struct block_li
}
tsd->reproduceskill_id = copy_skill;
- pc_setglobalreg(tsd, script->add_str("REPRODUCE_SKILL"), copy_skill);
- pc_setglobalreg(tsd, script->add_str("REPRODUCE_SKILL_LV"), lv);
+ pc_setglobalreg(tsd, script->add_variable("REPRODUCE_SKILL"), copy_skill);
+ pc_setglobalreg(tsd, script->add_variable("REPRODUCE_SKILL_LV"), lv);
tsd->status.skill[cidx].id = copy_skill;
tsd->status.skill[cidx].lv = lv;
@@ -3242,8 +3242,8 @@ static int skill_attack(int attack_type, struct block_list *src, struct block_li
lv = plagiarismlvl;
tsd->cloneskill_id = copy_skill;
- pc_setglobalreg(tsd, script->add_str("CLONE_SKILL"), copy_skill);
- pc_setglobalreg(tsd, script->add_str("CLONE_SKILL_LV"), lv);
+ pc_setglobalreg(tsd, script->add_variable("CLONE_SKILL"), copy_skill);
+ pc_setglobalreg(tsd, script->add_variable("CLONE_SKILL_LV"), lv);
tsd->status.skill[cidx].id = copy_skill;
tsd->status.skill[cidx].lv = lv;
@@ -6758,7 +6758,7 @@ static int skill_castend_nodamage_id(struct block_list *src, struct block_list *
}
sd->mission_mobid = id;
sd->mission_count = 0;
- pc_setglobalreg(sd,script->add_str("TK_MISSION_ID"), id);
+ pc_setglobalreg(sd,script->add_variable("TK_MISSION_ID"), id);
clif->mission_info(sd, id, 0);
clif->skill_nodamage(src,bl,skill_id,skill_lv,1);
}
@@ -8537,7 +8537,7 @@ static int skill_castend_nodamage_id(struct block_list *src, struct block_list *
if (skill_id == SL_SUPERNOVICE && dstsd && dstsd->die_counter && !(rnd()%100)) {
//Erase death count 1% of the casts
dstsd->die_counter = 0;
- pc_setglobalreg(dstsd,script->add_str("PC_DIE_COUNTER"), 0);
+ pc_setglobalreg(dstsd,script->add_variable("PC_DIE_COUNTER"), 0);
clif->specialeffect(bl, 0x152, AREA);
//SC_SOULLINK invokes status_calc_pc for us.
}
@@ -18486,7 +18486,7 @@ static int skill_produce_mix(struct map_session_data *sd, uint16 skill_id, int n
{ //Cooking items.
clif->specialeffect(&sd->bl, 608, AREA);
if( sd->cook_mastery < 1999 )
- pc_setglobalreg(sd, script->add_str("COOK_MASTERY"),sd->cook_mastery + ( 1 << ( (skill->dbs->produce_db[idx].itemlv - 11) / 2 ) ) * 5);
+ pc_setglobalreg(sd, script->add_variable("COOK_MASTERY"),sd->cook_mastery + ( 1 << ( (skill->dbs->produce_db[idx].itemlv - 11) / 2 ) ) * 5);
}
break;
}
@@ -18597,7 +18597,7 @@ static int skill_produce_mix(struct map_session_data *sd, uint16 skill_id, int n
{ //Cooking items.
clif->specialeffect(&sd->bl, 609, AREA);
if( sd->cook_mastery > 0 )
- pc_setglobalreg(sd, script->add_str("COOK_MASTERY"), sd->cook_mastery - ( 1 << ((skill->dbs->produce_db[idx].itemlv - 11) / 2) ) - ( ( ( 1 << ((skill->dbs->produce_db[idx].itemlv - 11) / 2) ) >> 1 ) * 3 ));
+ pc_setglobalreg(sd, script->add_variable("COOK_MASTERY"), sd->cook_mastery - ( 1 << ((skill->dbs->produce_db[idx].itemlv - 11) / 2) ) - ( ( ( 1 << ((skill->dbs->produce_db[idx].itemlv - 11) / 2) ) >> 1 ) * 3 ));
}
}
}
diff --git a/src/plugins/HPMHooking/HPMHooking.Defs.inc b/src/plugins/HPMHooking/HPMHooking.Defs.inc
index 94ca75f6e..cc093975f 100644
--- a/src/plugins/HPMHooking/HPMHooking.Defs.inc
+++ b/src/plugins/HPMHooking/HPMHooking.Defs.inc
@@ -6620,6 +6620,8 @@ typedef bool (*HPMHOOK_pre_script_config_read) (const char **filename, bool *imp
typedef bool (*HPMHOOK_post_script_config_read) (bool retVal___, const char *filename, bool imported);
typedef int (*HPMHOOK_pre_script_add_str) (const char **p);
typedef int (*HPMHOOK_post_script_add_str) (int retVal___, const char *p);
+typedef int (*HPMHOOK_pre_script_add_variable) (const char **varname);
+typedef int (*HPMHOOK_post_script_add_variable) (int retVal___, const char *varname);
typedef const char* (*HPMHOOK_pre_script_get_str) (int *id);
typedef const char* (*HPMHOOK_post_script_get_str) (const char* retVal___, int id);
typedef int (*HPMHOOK_pre_script_search_str) (const char **p);
diff --git a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
index 3b598cd0d..457bf90fe 100644
--- a/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
+++ b/src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
@@ -5142,6 +5142,8 @@ struct {
struct HPMHookPoint *HP_script_config_read_post;
struct HPMHookPoint *HP_script_add_str_pre;
struct HPMHookPoint *HP_script_add_str_post;
+ struct HPMHookPoint *HP_script_add_variable_pre;
+ struct HPMHookPoint *HP_script_add_variable_post;
struct HPMHookPoint *HP_script_get_str_pre;
struct HPMHookPoint *HP_script_get_str_post;
struct HPMHookPoint *HP_script_search_str_pre;
@@ -11705,6 +11707,8 @@ struct {
int HP_script_config_read_post;
int HP_script_add_str_pre;
int HP_script_add_str_post;
+ int HP_script_add_variable_pre;
+ int HP_script_add_variable_post;
int HP_script_get_str_pre;
int HP_script_get_str_post;
int HP_script_search_str_pre;
diff --git a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
index 70ea54928..41e6f9208 100644
--- a/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
+++ b/src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
@@ -2634,6 +2634,7 @@ struct HookingPointData HookingPoints[] = {
{ HP_POP(script->setarray_pc, HP_script_setarray_pc) },
{ HP_POP(script->config_read, HP_script_config_read) },
{ HP_POP(script->add_str, HP_script_add_str) },
+ { HP_POP(script->add_variable, HP_script_add_variable) },
{ HP_POP(script->get_str, HP_script_get_str) },
{ HP_POP(script->search_str, HP_script_search_str) },
{ HP_POP(script->setd_sub, HP_script_setd_sub) },
diff --git a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
index 4231eedb7..8ad18f843 100644
--- a/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
+++ b/src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
@@ -68495,6 +68495,33 @@ int HP_script_add_str(const char *p) {
}
return retVal___;
}
+int HP_script_add_variable(const char *varname) {
+ int hIndex = 0;
+ int retVal___ = 0;
+ if (HPMHooks.count.HP_script_add_variable_pre > 0) {
+ int (*preHookFunc) (const char **varname);
+ *HPMforce_return = false;
+ for (hIndex = 0; hIndex < HPMHooks.count.HP_script_add_variable_pre; hIndex++) {
+ preHookFunc = HPMHooks.list.HP_script_add_variable_pre[hIndex].func;
+ retVal___ = preHookFunc(&varname);
+ }
+ if (*HPMforce_return) {
+ *HPMforce_return = false;
+ return retVal___;
+ }
+ }
+ {
+ retVal___ = HPMHooks.source.script.add_variable(varname);
+ }
+ if (HPMHooks.count.HP_script_add_variable_post > 0) {
+ int (*postHookFunc) (int retVal___, const char *varname);
+ for (hIndex = 0; hIndex < HPMHooks.count.HP_script_add_variable_post; hIndex++) {
+ postHookFunc = HPMHooks.list.HP_script_add_variable_post[hIndex].func;
+ retVal___ = postHookFunc(retVal___, varname);
+ }
+ }
+ return retVal___;
+}
const char* HP_script_get_str(int id) {
int hIndex = 0;
const char* retVal___ = NULL;