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.
140 lines
4.9 KiB
C
140 lines
4.9 KiB
C
/*
|
|
* LocalMP multi-nation team country lists (`team1_countries` / `team2_countries`) and the
|
|
* in-battle chat objects of the host.
|
|
*
|
|
* Chat (2.61.0.37): when the host sends a message, chat_on_send (0x154f540) hands it to the host
|
|
* chat handler 0x133ba10 with Multiplayer+0x1f8 as its object instead of sending it to a server.
|
|
* The client never creates that object (a dedicated server does); the handler reads exactly two
|
|
* fields of it: [0] the Multiplayer and [1] an optional chat log writer, used only when non-null
|
|
* (0x133c40f). The host here gets that two-field object with no log writer, and its MPChat
|
|
* (Multiplayer+0x1f0) from the stock Multiplayer::initMPChat (0x5bd6a0).
|
|
*/
|
|
#include "hooks.h"
|
|
#include "hook_config.h"
|
|
#include "local_mp_internal.h"
|
|
#include "local_mp_offsets.h"
|
|
|
|
#include "MinHook.h"
|
|
|
|
#include <string.h>
|
|
|
|
#define MAX_TEAM_COUNTRIES 16u
|
|
|
|
typedef uint8_t (__fastcall *MpConstructLocalFn)(uint8_t *mp, void *mis, void *chat_settings);
|
|
typedef void (__fastcall *MpInitChatFn)(uint8_t *mp, void *chat_settings);
|
|
typedef void *(__fastcall *DagmemAllocFn)(size_t size);
|
|
|
|
static MpConstructLocalFn orig_mp_construct_local;
|
|
static MpInitChatFn fn_mp_init_chat;
|
|
static DagmemAllocFn fn_dagmem_alloc;
|
|
|
|
static void clear_team_country_tab(uint8_t *tab)
|
|
{
|
|
char **data = *(char ***)(tab + LMP_TAB_OFF_DATA);
|
|
uint32_t count = *(uint32_t *)(tab + LMP_TAB_OFF_COUNT);
|
|
uint32_t i;
|
|
|
|
if (data != NULL) {
|
|
for (i = 0; i < count; i++)
|
|
local_mp_mem_free(data[i]);
|
|
local_mp_mem_free(data);
|
|
}
|
|
*(char ***)(tab + LMP_TAB_OFF_DATA) = NULL;
|
|
*(void **)(tab + LMP_TAB_OFF_ALLOC) = g_local_mp_stdmem ? *g_local_mp_stdmem : NULL;
|
|
*(uint32_t *)(tab + LMP_TAB_OFF_COUNT) = 0;
|
|
*(uint32_t *)(tab + LMP_TAB_OFF_CAPACITY) = 0;
|
|
}
|
|
|
|
static void populate_team_country_tab(uint8_t *tab, const char *csv)
|
|
{
|
|
char tokens[MAX_TEAM_COUNTRIES][32];
|
|
uint32_t count = 0;
|
|
const char *p = csv;
|
|
char **arr;
|
|
uint32_t i;
|
|
|
|
clear_team_country_tab(tab);
|
|
if (p == NULL || *p == '\0' || g_local_mp_stdmem == NULL || *g_local_mp_stdmem == NULL)
|
|
return;
|
|
|
|
while (*p != '\0' && count < MAX_TEAM_COUNTRIES) {
|
|
const char *sep = strchr(p, ';');
|
|
size_t len = sep ? (size_t)(sep - p) : strlen(p);
|
|
if (len > 0 && len < sizeof(tokens[0])) {
|
|
memcpy(tokens[count], p, len);
|
|
tokens[count][len] = '\0';
|
|
count++;
|
|
}
|
|
if (sep == NULL)
|
|
break;
|
|
p = sep + 1;
|
|
}
|
|
if (count == 0)
|
|
return;
|
|
|
|
arr = (char **)local_mp_mem_alloc((size_t)count * sizeof(char *));
|
|
if (arr == NULL)
|
|
return;
|
|
for (i = 0; i < count; i++)
|
|
arr[i] = local_mp_strdup(tokens[i]);
|
|
|
|
*(char ***)(tab + LMP_TAB_OFF_DATA) = arr;
|
|
*(void **)(tab + LMP_TAB_OFF_ALLOC) = *g_local_mp_stdmem;
|
|
*(uint32_t *)(tab + LMP_TAB_OFF_COUNT) = count;
|
|
*(uint32_t *)(tab + LMP_TAB_OFF_CAPACITY) = count;
|
|
}
|
|
|
|
static void apply_custom_bot_team_countries(uint8_t *mp)
|
|
{
|
|
const void *bots_blk;
|
|
const char *team_a;
|
|
const char *team_b;
|
|
|
|
if (g_local_mp_mission_settings == NULL || g_lmp_datablock_get_str == NULL)
|
|
return;
|
|
bots_blk = g_local_mp_mission_settings + LMP_MIS_OFF_CUSTOM_BOTS;
|
|
team_a = g_lmp_datablock_get_str(bots_blk, "wtoTeamACountries", "");
|
|
team_b = g_lmp_datablock_get_str(bots_blk, "wtoTeamBCountries", "");
|
|
if (team_a != NULL && team_a[0] != '\0')
|
|
populate_team_country_tab(mp + LMP_MP_MGR_OFF_TEAM1_COUNTRIES, team_a);
|
|
if (team_b != NULL && team_b[0] != '\0')
|
|
populate_team_country_tab(mp + LMP_MP_MGR_OFF_TEAM2_COUNTRIES, team_b);
|
|
}
|
|
|
|
static uint8_t __fastcall hook_mp_construct_local(uint8_t *mp, void *mis, void *chat_settings)
|
|
{
|
|
uint8_t ok = orig_mp_construct_local(mp, mis, chat_settings);
|
|
if (!ok || mp == NULL)
|
|
return ok;
|
|
apply_custom_bot_team_countries(mp);
|
|
if (chat_settings != NULL && fn_mp_init_chat != NULL &&
|
|
*(void **)(mp + LMP_MP_MGR_OFF_MP_CHAT) == NULL) {
|
|
fn_mp_init_chat(mp, chat_settings);
|
|
}
|
|
if (fn_dagmem_alloc != NULL && *(void **)(mp + LMP_MP_MGR_OFF_CHAT_HOST) == NULL) {
|
|
void **chat_host = (void **)fn_dagmem_alloc(2u * sizeof(void *));
|
|
if (chat_host != NULL) {
|
|
chat_host[0] = mp;
|
|
chat_host[1] = NULL;
|
|
*(void **)(mp + LMP_MP_MGR_OFF_CHAT_HOST) = chat_host;
|
|
log_line("local_mp: created the host chat object for LocalMP");
|
|
}
|
|
}
|
|
return ok;
|
|
}
|
|
|
|
int install_local_mp_action_hooks(void)
|
|
{
|
|
uint8_t *p_construct = g_lmp.mp_construct_local;
|
|
|
|
fn_mp_init_chat = (MpInitChatFn)g_lmp.mp_init_chat;
|
|
fn_dagmem_alloc = (DagmemAllocFn)g_lmp.dagmem_alloc;
|
|
|
|
if (MH_CreateHook(p_construct, (void *)&hook_mp_construct_local, (void **)&orig_mp_construct_local) != MH_OK ||
|
|
MH_EnableHook(p_construct) != MH_OK) {
|
|
log_line("local_mp: failed to install the LocalMP construction hook");
|
|
return 0;
|
|
}
|
|
return 1;
|
|
}
|