Files
WT-Offline/native/wto-net/src/local_mp_awards.c
T
N0VAN0M4LY fdac56a036 refactor(native)!: load LocalMP values from the build configuration
wto_ws.dll no longer scans aces.exe or carries structure offsets of a game
build. It reads the values the patcher resolved (wto_ws.cfg native.* lines)
into g_lmp through one table that names, per module, which value fills which
field (local_mp_values.c), and installs each module whose values are all
present, in dependency order, instead of giving up on the whole bridge when
one subsystem is missing. When the settings were resolved for another
executable (PE time stamp and image size differ), the bridge stays off.

local_mp_offsets.h keeps the existing names so the module code reads as
before; only Dagor library layouts (dag::Vector, DataBlock), protocol enums,
the reflection buffer size and the two change request members with no reader
in the client remain constants. A few fields are derived where the client has
no instruction of its own for them (local_mp_values.c derive_values). The
signatures moved to patches/native, and the header-based check-offsets
command is gone: record-game-version and the launcher's patch check resolve
the native modules now.

Shared sites moved to local_mp_core (mission customBots, the player's unit
eid) so modules do not depend on each other for them.

Checked: DLL build (no warnings outside MinHook); root and launcher type
checks; check-patches on 2.61.0.37; version records for 2.61.0.37 and
2.61.0.43 (10 native modules each); a lab run of the 2.61.0.37 copy logs
239 native values and "9 of 9 LocalMP modules installed". Battles were not
played in this run.

BREAKING CHANGE: Rebuild game copies to generate the new native values in wto_ws.cfg. Use record-game-version.ts or the launcher patch check in place of wtotools check-offsets.
2026-11-29 12:26:11 +08:00

109 lines
4.4 KiB
C

/*
* 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 <string.h>
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;
}