/* * Reports the local player's combat events to the GUI scripts. * * Online, the battle server prices every combat event and sends it to the client * (packet 0xb03d -> GameSaveData::addScoreMessage), which raises the HUD script event * "InBattleReward". A LocalMP host has no battle server, so the kill and event hooks call * local_mp_report_award_event() instead. It raises the HUD script event * LMP_AWARD_EVENT_NAME carrying facts only (event code, victim class and name); the * scripts price it with the parameters sent by the local server, show the banner and keep * the record that the local server settles after the battle. Nothing here computes money. * * The event is queued with the same call addScoreMessage uses, but without its * "hudShowAwardMessages" option gate, so the record does not depend on a HUD setting. * Every engine helper below, and the queue's offset in GameSaveData, is captured from a call site * inside addScoreMessage (patches/native/local_mp_awards.jsonc). */ #include "hooks.h" #include "hook_config.h" #include "local_mp_internal.h" #include "local_mp_offsets.h" #include typedef void (__fastcall *BlkCtorFn)(void *blk); typedef void (__fastcall *BlkDtorFn)(void *blk); typedef void (__fastcall *BlkToOwnedFn)(void *blk); typedef void (__fastcall *BlkSetStrFn)(void *blk, const char *name, const char *value); typedef void (__fastcall *BlkSetIntFn)(void *blk, const char *name, const int32_t *value); typedef void (__fastcall *HudNotifyScriptFn)(void *queue, const char *event_name, const void *blk); static uint8_t **g_game_save_data; static BlkCtorFn fn_blk_ctor; static BlkDtorFn fn_blk_dtor; static BlkToOwnedFn fn_blk_to_owned; static BlkSetStrFn fn_blk_set_str; static BlkSetIntFn fn_blk_set_int; static HudNotifyScriptFn fn_hud_notify_script; /* Mirrors addScoreMessage: integer setters expect an owned DataBlock, string setters convert it. */ static void blk_set_int(uint8_t *blk, const char *name, int32_t value) { if (*(int32_t *)(blk + LMP_BLK_OFF_OWNED_STATE) != -1) fn_blk_to_owned(blk); fn_blk_set_int(blk, name, &value); } const char *local_mp_unit_exp_class(const uint8_t *unit) { const uint8_t *uinfo; const char *exp_class; if (unit == NULL) return NULL; uinfo = *(const uint8_t *const *)(unit + LMP_UNIT_OFF_INFO); if (uinfo == NULL) return NULL; exp_class = *(const char *const *)(uinfo + LMP_UNIT_INFO_OFF_EXP_CLASS); return (exp_class != NULL && exp_class[0] != '\0') ? exp_class : NULL; } void local_mp_report_award_event(const LocalMpAwardEvent *ev) { __declspec(align(16)) uint8_t blk[LMP_BLK_SIZE]; uint8_t *gsd = g_game_save_data ? *g_game_save_data : NULL; const char *victim_name = ev ? local_mp_unit_name(ev->victim) : NULL; const char *victim_class = ev ? local_mp_unit_exp_class(ev->victim) : NULL; if (ev == NULL || gsd == NULL || fn_hud_notify_script == NULL) return; memset(blk, 0, sizeof(blk)); fn_blk_ctor(blk); fn_blk_set_str(blk, "expClass", victim_class ? victim_class : ""); fn_blk_set_str(blk, "victim", victim_name ? victim_name : ""); fn_blk_set_str(blk, "messageModifier", ev->modifier ? ev->modifier : ""); blk_set_int(blk, "messageCode", (int32_t)ev->exp_event); blk_set_int(blk, "victimIsPlayer", ev->victim_is_player ? 1 : 0); blk_set_int(blk, "friendly", ev->friendly ? 1 : 0); blk_set_int(blk, "damage", ev->damage); fn_hud_notify_script(gsd + LMP_GSD_OFF_HUD_QUEUE, LMP_AWARD_EVENT_NAME, blk); fn_blk_dtor(blk); } /* The fact behind the award killStreak_bomber_nuclear_success, which online the battle server * judges itself; the event carries no fields. */ void local_mp_report_nuclear_strike(void) { __declspec(align(16)) uint8_t blk[LMP_BLK_SIZE]; uint8_t *gsd = g_game_save_data ? *g_game_save_data : NULL; if (gsd == NULL || fn_hud_notify_script == NULL) return; memset(blk, 0, sizeof(blk)); fn_blk_ctor(blk); fn_hud_notify_script(gsd + LMP_GSD_OFF_HUD_QUEUE, LMP_NUCLEAR_STRIKE_EVENT_NAME, blk); fn_blk_dtor(blk); } int install_local_mp_award_hooks(void) { g_game_save_data = (uint8_t **)g_lmp.game_save_data; fn_blk_ctor = (BlkCtorFn)g_lmp.blk_ctor; fn_blk_set_str = (BlkSetStrFn)g_lmp.blk_set_str; fn_blk_to_owned = (BlkToOwnedFn)g_lmp.blk_to_owned; fn_blk_set_int = (BlkSetIntFn)g_lmp.blk_set_int; fn_hud_notify_script = (HudNotifyScriptFn)g_lmp.hud_notify_script; fn_blk_dtor = (BlkDtorFn)g_lmp.blk_dtor; return 1; }