Files
WT-Offline/native/wto-net/src/local_mp_internal.h
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

95 lines
4.4 KiB
C

/*
* Shared internal state, resolved engine pointers, and subsystem interfaces
* for the LocalMP in-process host bridge.
*
* Addresses and structure offsets come from the build (local_mp_values.h); every detour is gated
* on local_mp_is_host().
*/
#pragma once
#include <stddef.h>
#include <stdint.h>
/* HUD script event raised for each combat event of the local player (local_mp_awards.c). */
#define LMP_AWARD_EVENT_NAME "wtoLocalMpExpEvent"
/* HUD script event raised when the local player's instant-win bomb explodes (local_mp_nuke.c). */
#define LMP_NUCLEAR_STRIKE_EVENT_NAME "wtoLocalMpNuclearStrike"
typedef char *(__fastcall *LmpGetPlayerCountryFn)(uint8_t *mis, int32_t pid, char *buf, int32_t buf_size);
typedef void (__fastcall *LmpSetPlayerGuiStateFn)(int32_t player_id, int32_t state);
typedef void (__fastcall *LmpAircraftChangeResultFn)(void *econ_state, int32_t err_code);
typedef void *(__fastcall *LmpGetUnitByEidFn)(uint32_t eid);
typedef void (__fastcall *LmpSetOwningMPlayerFn)(void *unit, void *mplayer, uint8_t f1, uint8_t set_pid);
typedef const char *(__fastcall *LmpDataBlockGetStrFn)(const void *blk, const char *name, const char *def);
/* One combat event of the local player, as facts only (see local_mp_awards.c). */
typedef struct LocalMpAwardEvent {
uint32_t exp_event; /* EXP_EVENT_* code (globalScripts/expEventConsts.nut) */
const uint8_t *victim; /* destroyed or damaged unit; NULL for a zone capture */
int victim_is_player; /* victim belongs to an MPlayer (player or bound bot) */
int friendly; /* victim was on the local player's team */
const char *modifier; /* stock messageModifier, e.g. "from_severe_damage", or NULL */
int32_t damage; /* naval award damage for EXP_EVENT_UNIT_DAMAGE, else 0 */
} LocalMpAwardEvent;
extern uint8_t **g_local_mp_multiplayer;
extern uint8_t **g_local_mp_app;
extern uint8_t **g_local_mp_mplayer;
extern uint8_t **g_local_mp_hero;
extern uint8_t *g_local_mp_mission_settings;
extern void ***g_local_mp_stdmem;
extern uint8_t ***g_local_mp_player_table;
extern uint32_t *g_local_mp_player_count;
extern LmpGetPlayerCountryFn g_lmp_get_player_country;
extern LmpSetPlayerGuiStateFn g_lmp_set_player_gui_state;
extern LmpAircraftChangeResultFn g_lmp_aircraft_change_result;
extern LmpGetUnitByEidFn g_lmp_get_unit_by_eid;
extern LmpSetOwningMPlayerFn g_lmp_set_owning_mplayer;
extern LmpDataBlockGetStrFn g_lmp_datablock_get_str;
int local_mp_is_host(void);
int local_mp_is_local_mplayer(const uint8_t *mp);
uint8_t *local_mp_econ_state(void);
uint8_t *local_mp_find_mplayer(int64_t user_id, uint8_t pid);
void *local_mp_mem_alloc(size_t size);
void local_mp_mem_free(void *ptr);
char *local_mp_strdup(const char *s);
const char *local_mp_unit_name(const uint8_t *unit);
/* Player state & slot tracking notifications shared with loadout module. */
void local_mp_players_queue_spawn(int32_t slot_id, int32_t spare_type, int is_silent);
/* Combat event reporting to the GUI scripts (local_mp_awards.c). */
void local_mp_report_award_event(const LocalMpAwardEvent *ev);
void local_mp_report_nuclear_strike(void);
/* A destroyed unit that is some player's mission support unit: its reference is freed once the
* player has been given back control (local_mp_support.c). */
void local_mp_support_unit_dead(const uint8_t *victim);
const char *local_mp_unit_exp_class(const uint8_t *unit);
/* Mission scores of combat events from the mission settings (local_mp_scores.c). */
float local_mp_score_param(const char *key);
float local_mp_event_score(const char *event, const uint8_t *unit, int victim_is_player);
/* Assist deduplication lifecycle shared between kill and event hooks. */
void local_mp_events_reset(void);
void local_mp_events_begin_death(const uint8_t *victim);
/* Shared MPlayer scoreboard helpers exposed by local_mp_kills.c. */
void local_mp_add_mplayer_score(uint8_t *mp, float delta, uint32_t event_id);
void local_mp_mark_mplayer_dirty(uint8_t *mp);
void local_mp_inc_mplayer_stat(uint8_t *mp, size_t off);
/* Module hook installers, called by install_local_mp_hooks() once the module's values are loaded. */
int install_local_mp_player_hooks(void);
int install_local_mp_loadout_hooks(void);
int install_local_mp_action_hooks(void);
int install_local_mp_award_hooks(void);
int install_local_mp_kill_hooks(void);
int install_local_mp_event_hooks(void);
int install_local_mp_score_reader(void);
int install_local_mp_nuke_hooks(void);
int install_local_mp_support_hooks(void);