- Scoreboard scores come from the local service: BattleEconomy missionScores() writes the official mission scores into the stock mission block customScoreParams, which the client copies into MissionSettings+0x6d8 without reading it; local_mp_scores.c reads them with DataBlock::getReal. The hardcoded scores and the death score go. - countActivePlayers already counts players with a living vehicle; the only LocalMP gap is its filter skipping bots (MPlayer+0x1d8 bit 7). A one-byte exe patch drops that filter bit instead of a rewrite hook. - ucavLaunch returns early on a host; an exe patch skips that return instead of clearing the global host flag around the call. - onBecameDead no longer runs with isLocalMP cleared: that only queued an EventOnPlayerDeath stock LocalMP skips on purpose, and broke the local player id remap inside the function. - The host chat object keeps its two-field layout, now documented from the host chat handler that reads it.
144 lines
5.3 KiB
C
144 lines
5.3 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(const uint8_t *text, size_t text_size)
|
|
{
|
|
uint8_t *p_construct = local_mp_scan_unique(text, text_size, "Multiplayer::constructLocalMP", LMP_SIG_MP_CONSTRUCT_LOCAL);
|
|
uint8_t *p_init_chat = local_mp_scan_unique(text, text_size, "Multiplayer::initMPChat", LMP_SIG_MP_INIT_CHAT);
|
|
uint8_t *p_set_from = local_mp_scan_unique(text, text_size, "DataBlock::setFrom", LMP_SIG_DATABLOCK_SET_FROM);
|
|
|
|
if (!p_construct || !p_init_chat || !p_set_from)
|
|
return 0;
|
|
fn_mp_init_chat = (MpInitChatFn)p_init_chat;
|
|
fn_dagmem_alloc = (DagmemAllocFn)local_mp_resolve_rip(p_set_from + 0x25, 1, 5);
|
|
|
|
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;
|
|
}
|