summaryrefslogtreecommitdiff
path: root/src/map/npc.c
diff options
context:
space:
mode:
authorshennetsind <ind@henn.et>2014-03-14 13:41:30 -0300
committershennetsind <ind@henn.et>2014-03-14 13:41:30 -0300
commitf4b1ff7426b1c4cd5e8cac37f7e3983cc03c706e (patch)
tree68b403b855daca7d11b86b02fcf2d95b8de974b4 /src/map/npc.c
parent571d9e25008d8b386e28d7f1fd02f2690edf1f8c (diff)
downloadhercules-f4b1ff7426b1c4cd5e8cac37f7e3983cc03c706e.tar.gz
hercules-f4b1ff7426b1c4cd5e8cac37f7e3983cc03c706e.tar.bz2
hercules-f4b1ff7426b1c4cd5e8cac37f7e3983cc03c706e.tar.xz
hercules-f4b1ff7426b1c4cd5e8cac37f7e3983cc03c706e.zip
Added internal awareness of active script instances
Fixes the following issues: - donpcevent could cause a crash when used to a event of the same npc - input/other-dialog-interactions could cause a crash when sending data to a disabled-fakenpc-id'd. Special Thanks to Haruna, ossi0110. Signed-off-by: shennetsind <ind@henn.et>
Diffstat (limited to 'src/map/npc.c')
-rw-r--r--src/map/npc.c16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/map/npc.c b/src/map/npc.c
index 7933f6d43..f77359b5f 100644
--- a/src/map/npc.c
+++ b/src/map/npc.c
@@ -1185,21 +1185,21 @@ int npc_click(struct map_session_data* sd, struct npc_data* nd)
/*==========================================
*
*------------------------------------------*/
-int npc_scriptcont(struct map_session_data* sd, int id, bool closing)
-{
+int npc_scriptcont(struct map_session_data* sd, int id, bool closing) {
+ struct block_list *target = map->id2bl(id);
nullpo_retr(1, sd);
if( id != sd->npc_id ){
TBL_NPC* nd_sd=(TBL_NPC*)map->id2bl(sd->npc_id);
- TBL_NPC* nd=(TBL_NPC*)map->id2bl(id);
+ TBL_NPC* nd = BL_CAST(BL_NPC, target);
ShowDebug("npc_scriptcont: %s (sd->npc_id=%d) is not %s (id=%d).\n",
nd_sd?(char*)nd_sd->name:"'Unknown NPC'", (int)sd->npc_id,
nd?(char*)nd->name:"'Unknown NPC'", (int)id);
return 1;
}
-
+
if(id != npc->fake_nd->bl.id) { // Not item script
- if ((npc->checknear(sd,map->id2bl(id))) == NULL){
+ if ((npc->checknear(sd,target)) == NULL){
ShowWarning("npc_scriptcont: failed npc->checknear test.\n");
return 1;
}
@@ -1219,7 +1219,10 @@ int npc_scriptcont(struct map_session_data* sd, int id, bool closing)
**/
if( sd->progressbar.npc_id && DIFF_TICK(sd->progressbar.timeout,timer->gettick()) > 0 )
return 1;
-
+
+ if( !sd->st )
+ return 1;
+
if( closing && sd->st->state == CLOSE )
sd->st->state = END;
@@ -2226,7 +2229,6 @@ int npc_unload(struct npc_data* nd, bool single) {
aFree(nd->u.scr.timer_event);
if (nd->src_id == 0) {
if(nd->u.scr.script) {
- script->stop_instances(nd->u.scr.script);
script->free_code(nd->u.scr.script);
nd->u.scr.script = NULL;
}