/* Validate recipient ownership at the two outgoing hit-feedback dispatch points. */ #include "local_mp_internal.h" #include "local_mp_offsets.h" #include typedef void (__fastcall *SendScriptNetEventFn)(void *manager, uint8_t broadcast, uint32_t destination, const void *event, const char *event_name, const void *recipient_args, const void *recipient_filter); typedef void (__fastcall *NotifyHudScriptFn)(void *hud, int32_t event_id, const void *data); /* The CmdShowHitMark unicast constructor writes 0x0001001c6c52bfea followed by its victim EID. * The stock sender handles event destruction when its flags require it. This event is plain data. */ typedef struct HitMarkEvent { uint32_t type; uint16_t size; uint16_t flags; uint32_t victim; } HitMarkEvent; enum { HIT_MARK_EVENT_TYPE = 0x6c52bfea, HIT_MARK_EVENT_SIZE = 0x1c, ECS_EVENT_UNICAST = 1 }; enum { HUD_HINT_CHANGE_SHELL_TYPE = 0xc5 }; static SendScriptNetEventFn original_send_script_event; static NotifyHudScriptFn original_notify_hud_script; static int should_drop_hit_mark(uint8_t broadcast, uint32_t destination, const HitMarkEvent *event) { if (event == NULL || event->type != HIT_MARK_EVENT_TYPE || event->size != HIT_MARK_EVENT_SIZE || event->flags != ECS_EVENT_UNICAST || broadcast || !local_mp_is_host()) return 0; const uint8_t *attacker = g_lmp_get_unit_by_eid(destination); const uint8_t *victim = g_lmp_get_unit_by_eid(event->victim); return !local_mp_is_view_hit(attacker, victim); } static void __fastcall hook_send_script_event(void *manager, uint8_t broadcast, uint32_t destination, const void *event, const char *event_name, const void *recipient_args, const void *recipient_filter) { if (!should_drop_hit_mark(broadcast, destination, event)) original_send_script_event(manager, broadcast, destination, event, event_name, recipient_args, recipient_filter); } static void __fastcall hook_notify_hud_script(void *hud, int32_t event_id, const void *data) { if (event_id == HUD_HINT_CHANGE_SHELL_TYPE && (uintptr_t)_ReturnAddress() == (uintptr_t)g_lmp.hit_shell_hint_call + LMP_REL32_CALL_SIZE && local_mp_is_host() && !local_mp_has_enemy_hit_feedback()) return; original_notify_hud_script(hud, event_id, data); } int install_local_mp_hit_feedback_hooks(void) { if (!local_mp_damage_notifications_ready()) return 0; const LocalMpHookSpec hooks[] = { { "send_script_net_event", g_lmp.hit_mark_send, (void *)&hook_send_script_event, (void **)&original_send_script_event }, { "notify_shell_hint", g_lmp.hit_shell_hint_notify, (void *)&hook_notify_hud_script, (void **)&original_notify_hud_script }, }; return local_mp_queue_hooks("local_mp_hit_feedback", hooks, sizeof(hooks) / sizeof(hooks[0])); }