Skip to content

Commit

Permalink
Added option to synchronize flinch animation with walk delay
Browse files Browse the repository at this point in the history
Interrupts walking and applies walk delay at the same time as the client reproduces the flinch animation. Improves positional lag.
  • Loading branch information
csnv committed Sep 17, 2023
1 parent 3faa147 commit 527ef11
Show file tree
Hide file tree
Showing 10 changed files with 65 additions and 2 deletions.
4 changes: 4 additions & 0 deletions src/config/core.h
Original file line number Diff line number Diff line change
Expand Up @@ -100,6 +100,10 @@
/// Uncomment for use with Nemo patch ExtendOldCashShopPreview
//#define ENABLE_OLD_CASHSHOP_PREVIEW_PATCH

/// Uncomment to allow flinch animation and walk delay to be synced
/// Reduces positional lag when getting hit
//#define WALKDELAY_SYNC

/**
* No settings past this point
**/
Expand Down
4 changes: 3 additions & 1 deletion src/map/battle.c
Original file line number Diff line number Diff line change
Expand Up @@ -350,7 +350,9 @@ static int battle_delay_damage(int64 tick, int amotion, struct block_list *src,
if (src->type == BL_PC) {
BL_UCAST(BL_PC, src)->delayed_damage++;
}

#ifdef WALKDELAY_SYNC
timer->add(tick + ddelay, unit->set_walkdelay_timer, target->id, ddelay);
#endif
timer->add(tick+amotion, battle->delay_damage_sub, 0, (intptr_t)dat);

return 0;
Expand Down
10 changes: 9 additions & 1 deletion src/map/clif.c
Original file line number Diff line number Diff line change
Expand Up @@ -5146,6 +5146,10 @@ static int clif_damage(struct block_list *src, struct block_list *dst, int sdela
#endif

type = clif_calc_delay(type,div,damage+damage2,ddelay);
#ifdef WALKDELAY_SYNC
// Send adjusted delay to client
ddelay = clif->calc_walkdelay(dst, ddelay, type, damage + damage2, div);
#endif

p.PacketType = damageType;
p.GID = src->id;
Expand Down Expand Up @@ -5191,7 +5195,11 @@ static int clif_damage(struct block_list *src, struct block_list *dst, int sdela
}

//Return adjusted can't walk delay for further processing.
return clif->calc_walkdelay(dst,ddelay,type,damage+damage2,div);
#ifdef WALKDELAY_SYNC
return ddelay;
#else
return clif->calc_walkdelay(dst, ddelay, type, damage + damage2, div);
#endif
}

/*==========================================
Expand Down
2 changes: 2 additions & 0 deletions src/map/status.c
Original file line number Diff line number Diff line change
Expand Up @@ -408,8 +408,10 @@ static int status_damage(struct block_list *src, struct block_list *target, int6

if (st->hp || (flag&8)) {
//Still lives or has been dead before this damage.
#ifndef WALKDELAY_SYNC
if (walkdelay)
unit->set_walkdelay(target, timer->gettick(), walkdelay, 0);
#endif
return (int)(hp+sp);
}

Expand Down
12 changes: 12 additions & 0 deletions src/map/unit.c
Original file line number Diff line number Diff line change
Expand Up @@ -1345,6 +1345,17 @@ static int unit_resume_running(int tid, int64 tick, int id, intptr_t data)

}

/*==========================================
* Apply walk delay timer
*------------------------------------------*/
static int unit_set_walkdelay_timer(int tid, int64 tick, int id, intptr_t data) {
struct block_list* bl = map->id2bl(id);
if (bl == NULL)
return 1;

unit->set_walkdelay(bl, tick, (int)data, 0);
return 0;
}

/*==========================================
* Applies walk delay to character, considering that
Expand Down Expand Up @@ -3236,6 +3247,7 @@ void unit_defaults(void)
unit->is_walking = unit_is_walking;
unit->can_move = unit_can_move;
unit->resume_running = unit_resume_running;
unit->set_walkdelay_timer = unit_set_walkdelay_timer;
unit->set_walkdelay = unit_set_walkdelay;
unit->skilluse_id2 = unit_skilluse_id2;
unit->skilluse_pos = unit_skilluse_pos;
Expand Down
1 change: 1 addition & 0 deletions src/map/unit.h
Original file line number Diff line number Diff line change
Expand Up @@ -129,6 +129,7 @@ struct unit_interface {
int (*is_walking) (struct block_list *bl);
int (*can_move) (struct block_list *bl);
int (*resume_running) (int tid, int64 tick, int id, intptr_t data);
int (*set_walkdelay_timer) (int tid, int64 tick, int id, intptr_t data);
int (*set_walkdelay) (struct block_list *bl, int64 tick, int delay, int type);
int (*skilluse_id2) (struct block_list *src, int target_id, uint16 skill_id, uint16 skill_lv, int casttime, int castcancel);
int (*skilluse_pos) (struct block_list *src, short skill_x, short skill_y, uint16 skill_id, uint16 skill_lv);
Expand Down
2 changes: 2 additions & 0 deletions src/plugins/HPMHooking/HPMHooking.Defs.inc
Original file line number Diff line number Diff line change
Expand Up @@ -9596,6 +9596,8 @@ typedef int (*HPMHOOK_pre_unit_can_move) (struct block_list **bl);
typedef int (*HPMHOOK_post_unit_can_move) (int retVal___, struct block_list *bl);
typedef int (*HPMHOOK_pre_unit_resume_running) (int *tid, int64 *tick, int *id, intptr_t *data);
typedef int (*HPMHOOK_post_unit_resume_running) (int retVal___, int tid, int64 tick, int id, intptr_t data);
typedef int (*HPMHOOK_pre_unit_set_walkdelay_timer) (int *tid, int64 *tick, int *id, intptr_t *data);
typedef int (*HPMHOOK_post_unit_set_walkdelay_timer) (int retVal___, int tid, int64 tick, int id, intptr_t data);
typedef int (*HPMHOOK_pre_unit_set_walkdelay) (struct block_list **bl, int64 *tick, int *delay, int *type);
typedef int (*HPMHOOK_post_unit_set_walkdelay) (int retVal___, struct block_list *bl, int64 tick, int delay, int type);
typedef int (*HPMHOOK_pre_unit_skilluse_id2) (struct block_list **src, int *target_id, uint16 *skill_id, uint16 *skill_lv, int *casttime, int *castcancel);
Expand Down
4 changes: 4 additions & 0 deletions src/plugins/HPMHooking/HPMHooking_map.HPMHooksCore.inc
Original file line number Diff line number Diff line change
Expand Up @@ -7494,6 +7494,8 @@ struct {
struct HPMHookPoint *HP_unit_can_move_post;
struct HPMHookPoint *HP_unit_resume_running_pre;
struct HPMHookPoint *HP_unit_resume_running_post;
struct HPMHookPoint *HP_unit_set_walkdelay_timer_pre;
struct HPMHookPoint *HP_unit_set_walkdelay_timer_post;
struct HPMHookPoint *HP_unit_set_walkdelay_pre;
struct HPMHookPoint *HP_unit_set_walkdelay_post;
struct HPMHookPoint *HP_unit_skilluse_id2_pre;
Expand Down Expand Up @@ -15025,6 +15027,8 @@ struct {
int HP_unit_can_move_post;
int HP_unit_resume_running_pre;
int HP_unit_resume_running_post;
int HP_unit_set_walkdelay_timer_pre;
int HP_unit_set_walkdelay_timer_post;
int HP_unit_set_walkdelay_pre;
int HP_unit_set_walkdelay_post;
int HP_unit_skilluse_id2_pre;
Expand Down
1 change: 1 addition & 0 deletions src/plugins/HPMHooking/HPMHooking_map.HookingPoints.inc
Original file line number Diff line number Diff line change
Expand Up @@ -3835,6 +3835,7 @@ struct HookingPointData HookingPoints[] = {
{ HP_POP(unit->is_walking, HP_unit_is_walking) },
{ HP_POP(unit->can_move, HP_unit_can_move) },
{ HP_POP(unit->resume_running, HP_unit_resume_running) },
{ HP_POP(unit->set_walkdelay_timer, HP_unit_set_walkdelay_timer) },
{ HP_POP(unit->set_walkdelay, HP_unit_set_walkdelay) },
{ HP_POP(unit->skilluse_id2, HP_unit_skilluse_id2) },
{ HP_POP(unit->skilluse_pos, HP_unit_skilluse_pos) },
Expand Down
27 changes: 27 additions & 0 deletions src/plugins/HPMHooking/HPMHooking_map.Hooks.inc
Original file line number Diff line number Diff line change
Expand Up @@ -100199,6 +100199,33 @@ int HP_unit_resume_running(int tid, int64 tick, int id, intptr_t data) {
}
return retVal___;
}
int HP_unit_set_walkdelay_timer(int tid, int64 tick, int id, intptr_t data) {
int hIndex = 0;
int retVal___ = 0;
if (HPMHooks.count.HP_unit_set_walkdelay_timer_pre > 0) {
int (*preHookFunc) (int *tid, int64 *tick, int *id, intptr_t *data);
*HPMforce_return = false;
for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_set_walkdelay_timer_pre; hIndex++) {
preHookFunc = HPMHooks.list.HP_unit_set_walkdelay_timer_pre[hIndex].func;
retVal___ = preHookFunc(&tid, &tick, &id, &data);
}
if (*HPMforce_return) {
*HPMforce_return = false;
return retVal___;
}
}
{
retVal___ = HPMHooks.source.unit.set_walkdelay_timer(tid, tick, id, data);
}
if (HPMHooks.count.HP_unit_set_walkdelay_timer_post > 0) {
int (*postHookFunc) (int retVal___, int tid, int64 tick, int id, intptr_t data);
for (hIndex = 0; hIndex < HPMHooks.count.HP_unit_set_walkdelay_timer_post; hIndex++) {
postHookFunc = HPMHooks.list.HP_unit_set_walkdelay_timer_post[hIndex].func;
retVal___ = postHookFunc(retVal___, tid, tick, id, data);
}
}
return retVal___;
}
int HP_unit_set_walkdelay(struct block_list *bl, int64 tick, int delay, int type) {
int hIndex = 0;
int retVal___ = 0;
Expand Down

0 comments on commit 527ef11

Please sign in to comment.