chore(battle): snapshot the LocalMP rework baseline
Records the uncommitted battle-session work exactly as it was left (local service matchmaking, settlement, chat, native LocalMP hooks, battle gui/exe patches) so the following review and rework commits show every correction as a diff against this state. This commit is not reviewed and is known to be incomplete: in-game testing reported wrong settlement rewards, single-country teams, missing random/fixed supplement slots, misattributed hit messages and other regressions. Do not merge this branch before the rework lands.
This commit is contained in:
1 parent
5c9204c031
commit
b260d2899e
97 files changed
+7676
-396
No files matched your search
@@ -22,6 +22,7 @@ New-Item -ItemType Directory -Force $obj | Out-Null
|
||||
|
||||
$sources = @(
|
||||
"$src\dll_main.c", "$src\hook_config.c", "$src\redirect_rules.c", "$src\resolver_hooks.c", "$src\connection_hooks.c",
|
||||
"$src\local_mp_core.c", "$src\local_mp_players.c", "$src\local_mp_loadout.c", "$src\local_mp_actions.c", "$src\local_mp_ledger.c", "$src\local_mp_kills.c", "$src\local_mp_events.c",
|
||||
"$mh\src\hook.c", "$mh\src\buffer.c", "$mh\src\trampoline.c", "$mh\src\hde\hde64.c"
|
||||
) | ForEach-Object { '"' + (Resolve-Path $_) + '"' }
|
||||
|
||||
|
||||
@@ -37,7 +37,10 @@ static int install(void)
|
||||
g_ws2 = GetModuleHandleW(L"ws2_32.dll");
|
||||
if (g_ws2 == NULL || MH_Initialize() != MH_OK)
|
||||
return 0;
|
||||
return install_resolver_hooks() && install_connection_hooks();
|
||||
if (!install_resolver_hooks() || !install_connection_hooks())
|
||||
return 0;
|
||||
install_local_mp_hooks();
|
||||
return 1;
|
||||
}
|
||||
|
||||
BOOL WINAPI DllMain(HINSTANCE instance, DWORD reason, LPVOID reserved)
|
||||
|
||||
@@ -9,3 +9,4 @@ int hook_export(const char *name, void *replacement, void **original);
|
||||
|
||||
int install_resolver_hooks(void);
|
||||
int install_connection_hooks(void);
|
||||
void install_local_mp_hooks(void);
|
||||
@@ -0,0 +1,206 @@
|
||||
/*
|
||||
* LocalMP multi-nation team country lists (`team1_countries` / `team2_countries`),
|
||||
* MPChat / MPChatHost initialization, UCAV recon drone bridge, and active-player count
|
||||
* bridge for CTA ticket bleed rules.
|
||||
*/
|
||||
#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);
|
||||
typedef int64_t (__fastcall *UcavLaunchFn)(void *a1, void *a2, void *a3, void *a4);
|
||||
typedef int32_t (__fastcall *CountActivePlayersFn)(int32_t team, uint8_t include_connecting);
|
||||
|
||||
static MpConstructLocalFn orig_mp_construct_local;
|
||||
static MpInitChatFn fn_mp_init_chat;
|
||||
static DagmemAllocFn fn_dagmem_alloc;
|
||||
static UcavLaunchFn orig_ucav_launch;
|
||||
static CountActivePlayersFn orig_count_active_players;
|
||||
|
||||
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: initialized multi-nation bot teams and MPChat for LocalMP");
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int64_t __fastcall hook_ucav_launch(void *a1, void *a2, void *a3, void *a4)
|
||||
{
|
||||
int64_t res;
|
||||
|
||||
if (!local_mp_is_host())
|
||||
return orig_ucav_launch(a1, a2, a3, a4);
|
||||
|
||||
(*g_local_mp_multiplayer)[LMP_MP_MGR_OFF_IS_HOST] = 0;
|
||||
res = orig_ucav_launch(a1, a2, a3, a4);
|
||||
if (*g_local_mp_multiplayer != NULL)
|
||||
(*g_local_mp_multiplayer)[LMP_MP_MGR_OFF_IS_HOST] = 1;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int is_unit_alive_for_tickets(uint32_t eid)
|
||||
{
|
||||
uint8_t *unit;
|
||||
|
||||
if (eid == 0 || g_lmp_get_unit_by_eid == NULL)
|
||||
return 0;
|
||||
unit = (uint8_t *)g_lmp_get_unit_by_eid(eid);
|
||||
if (unit == NULL || *(uint16_t *)(unit + LMP_UNIT_OFF_BAIL_STATE) != 0)
|
||||
return 0;
|
||||
if (*(uint32_t *)(unit + LMP_UNIT_OFF_ALIVE_STATE) == 0 &&
|
||||
*(uint16_t *)(unit + LMP_UNIT_OFF_TYPE) != LMP_UNIT_TYPE_HELICOPTER)
|
||||
return 0;
|
||||
return (*(uint32_t *)(unit + LMP_UNIT_OFF_DEAD_FLAGS) & LMP_UNIT_DEAD_FLAGS_MASK) == 0;
|
||||
}
|
||||
|
||||
static int32_t __fastcall hook_count_active_players(int32_t team, uint8_t include_connecting)
|
||||
{
|
||||
uint8_t **table;
|
||||
uint32_t count;
|
||||
uint32_t i;
|
||||
int32_t alive = 0;
|
||||
|
||||
if (!local_mp_is_host())
|
||||
return orig_count_active_players(team, include_connecting);
|
||||
|
||||
table = g_local_mp_player_table ? *g_local_mp_player_table : NULL;
|
||||
count = g_local_mp_player_count ? *g_local_mp_player_count : 0;
|
||||
if (table == NULL || count == 0)
|
||||
return orig_count_active_players(team, include_connecting);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
uint8_t *mp = table[i];
|
||||
if (mp == NULL)
|
||||
continue;
|
||||
if ((*(uint32_t *)(mp + LMP_MP_OFF_FLAGS) & LMP_MP_FLAG_SPECTATOR_MASK) != 0)
|
||||
continue;
|
||||
if (team > 0 && mp[LMP_MP_OFF_TEAM] != (uint8_t)team)
|
||||
continue;
|
||||
if (is_unit_alive_for_tickets(*(uint32_t *)(mp + LMP_MP_OFF_UNIT_EID)) ||
|
||||
is_unit_alive_for_tickets(*(uint32_t *)(mp + LMP_MP_OFF_SUPPORT_UNIT_EID)))
|
||||
alive++;
|
||||
}
|
||||
return alive;
|
||||
}
|
||||
|
||||
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);
|
||||
uint8_t *p_ucav = local_mp_scan_unique(text, text_size, "ucavLaunch", LMP_SIG_UCAV_LAUNCH);
|
||||
uint8_t *p_count_active = local_mp_scan_unique(text, text_size, "countActivePlayers", LMP_SIG_COUNT_ACTIVE_PLAYERS);
|
||||
|
||||
if (!p_construct || !p_init_chat || !p_set_from || !p_ucav || !p_count_active)
|
||||
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 ||
|
||||
MH_CreateHook(p_ucav, (void *)&hook_ucav_launch, (void **)&orig_ucav_launch) != MH_OK ||
|
||||
MH_EnableHook(p_ucav) != MH_OK ||
|
||||
MH_CreateHook(p_count_active, (void *)&hook_count_active_players, (void **)&orig_count_active_players) != MH_OK ||
|
||||
MH_EnableHook(p_count_active) != MH_OK) {
|
||||
log_line("local_mp: failed to install action or active-player hooks");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,290 @@
|
||||
/*
|
||||
* Core signature scanner, RIP-relative address resolver, Dagor allocator helpers,
|
||||
* and engine global discovery for the LocalMP in-process host bridge.
|
||||
*/
|
||||
#include "hooks.h"
|
||||
#include "hook_config.h"
|
||||
#include "local_mp_internal.h"
|
||||
#include "local_mp_offsets.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
typedef void *(__fastcall *DagorMemAllocFn)(void *alloc_self, size_t size);
|
||||
typedef void (__fastcall *DagorMemFreeFn)(void *alloc_self, void *ptr);
|
||||
|
||||
uint8_t **g_local_mp_multiplayer;
|
||||
uint8_t **g_local_mp_app;
|
||||
uint8_t **g_local_mp_mplayer;
|
||||
uint8_t **g_local_mp_hero;
|
||||
uint8_t *g_local_mp_mission_settings;
|
||||
void ***g_local_mp_stdmem;
|
||||
uint8_t ***g_local_mp_player_table;
|
||||
uint32_t *g_local_mp_player_count;
|
||||
|
||||
LmpGetPlayerCountryFn g_lmp_get_player_country;
|
||||
LmpSetPlayerGuiStateFn g_lmp_set_player_gui_state;
|
||||
LmpAircraftChangeResultFn g_lmp_aircraft_change_result;
|
||||
LmpGetUnitByEidFn g_lmp_get_unit_by_eid;
|
||||
LmpSetOwningMPlayerFn g_lmp_set_owning_mplayer;
|
||||
LmpDataBlockGetStrFn g_lmp_datablock_get_str;
|
||||
|
||||
static int hex_nibble(char c)
|
||||
{
|
||||
if (c >= '0' && c <= '9') return c - '0';
|
||||
if (c >= 'a' && c <= 'f') return c - 'a' + 10;
|
||||
if (c >= 'A' && c <= 'F') return c - 'A' + 10;
|
||||
return -1;
|
||||
}
|
||||
|
||||
static size_t parse_pattern(const char *spec, uint8_t *bytes, uint8_t *mask, size_t cap)
|
||||
{
|
||||
size_t n = 0;
|
||||
const char *p = spec;
|
||||
while (*p != '\0') {
|
||||
while (*p == ' ') p++;
|
||||
if (*p == '\0') break;
|
||||
if (n >= cap) return 0;
|
||||
if (p[0] == '?' && p[1] == '?') {
|
||||
bytes[n] = 0;
|
||||
mask[n] = 0;
|
||||
p += 2;
|
||||
} else {
|
||||
int hi = hex_nibble(p[0]);
|
||||
int lo = hex_nibble(p[1]);
|
||||
if (hi < 0 || lo < 0) return 0;
|
||||
bytes[n] = (uint8_t)((hi << 4) | lo);
|
||||
mask[n] = 1;
|
||||
p += 2;
|
||||
}
|
||||
n++;
|
||||
}
|
||||
return n;
|
||||
}
|
||||
|
||||
uint8_t *local_mp_scan_unique(const uint8_t *base, size_t size, const char *name, const char *spec)
|
||||
{
|
||||
uint8_t pat[192];
|
||||
uint8_t mask[192];
|
||||
size_t len = parse_pattern(spec, pat, mask, sizeof(pat));
|
||||
uint8_t *hit = NULL;
|
||||
size_t i, j;
|
||||
|
||||
if (len == 0 || size < len) {
|
||||
log_line("local_mp: invalid pattern for %s", name);
|
||||
return NULL;
|
||||
}
|
||||
for (i = 0; i <= size - len; i++) {
|
||||
for (j = 0; j < len; j++) {
|
||||
if (mask[j] && base[i + j] != pat[j])
|
||||
break;
|
||||
}
|
||||
if (j == len) {
|
||||
if (hit != NULL) {
|
||||
log_line("local_mp: ambiguous signature for %s", name);
|
||||
return NULL;
|
||||
}
|
||||
hit = (uint8_t *)(base + i);
|
||||
}
|
||||
}
|
||||
if (hit == NULL)
|
||||
log_line("local_mp: signature not found for %s", name);
|
||||
return hit;
|
||||
}
|
||||
|
||||
void *local_mp_resolve_rip(const uint8_t *insn, size_t disp_off, size_t insn_len)
|
||||
{
|
||||
int32_t disp = 0;
|
||||
memcpy(&disp, insn + disp_off, sizeof(disp));
|
||||
return (void *)(insn + insn_len + (intptr_t)disp);
|
||||
}
|
||||
|
||||
int local_mp_is_host(void)
|
||||
{
|
||||
uint8_t *mp = g_local_mp_multiplayer ? *g_local_mp_multiplayer : NULL;
|
||||
return mp != NULL &&
|
||||
mp[LMP_MP_MGR_OFF_IS_HOST] == 1 &&
|
||||
mp[LMP_MP_MGR_OFF_IS_LOCAL_MP] == 1;
|
||||
}
|
||||
|
||||
int local_mp_is_local_mplayer(const uint8_t *mp)
|
||||
{
|
||||
uint8_t *local_mp = g_local_mp_mplayer ? *g_local_mp_mplayer : NULL;
|
||||
if (mp == NULL)
|
||||
return 0;
|
||||
return mp == local_mp || mp[LMP_MP_OFF_PID] == 0;
|
||||
}
|
||||
|
||||
uint8_t *local_mp_econ_state(void)
|
||||
{
|
||||
uint8_t *app = g_local_mp_app ? *g_local_mp_app : NULL;
|
||||
uint8_t *holder = app ? *(uint8_t **)(app + LMP_APP_OFF_ECON_HOLDER) : NULL;
|
||||
return holder ? *(uint8_t **)(holder + LMP_ECON_HOLDER_OFF_STATE) : NULL;
|
||||
}
|
||||
|
||||
uint8_t *local_mp_find_mplayer(int64_t user_id, uint8_t pid)
|
||||
{
|
||||
uint8_t **table = g_local_mp_player_table ? *g_local_mp_player_table : NULL;
|
||||
uint32_t count = g_local_mp_player_count ? *g_local_mp_player_count : 0;
|
||||
uint32_t i;
|
||||
|
||||
if (table == NULL || count == 0)
|
||||
return NULL;
|
||||
if (user_id != -1 && user_id != 0) {
|
||||
for (i = 0; i < count; i++) {
|
||||
uint8_t *mp = table[i];
|
||||
if (mp != NULL && *(int64_t *)(mp + LMP_MP_OFF_USER_ID) == user_id)
|
||||
return mp;
|
||||
}
|
||||
}
|
||||
if (pid != 0xffu) {
|
||||
uint32_t slot = (pid == 0xfau) ? 0u : (uint32_t)pid;
|
||||
if (slot < count && table[slot] != NULL)
|
||||
return table[slot];
|
||||
}
|
||||
return NULL;
|
||||
}
|
||||
|
||||
void *local_mp_mem_alloc(size_t size)
|
||||
{
|
||||
void **mem = g_local_mp_stdmem ? *g_local_mp_stdmem : NULL;
|
||||
void **vtable;
|
||||
|
||||
if (size == 0 || mem == NULL || *mem == NULL)
|
||||
return NULL;
|
||||
vtable = (void **)(*mem);
|
||||
return ((DagorMemAllocFn)vtable[3])(mem, size);
|
||||
}
|
||||
|
||||
void local_mp_mem_free(void *ptr)
|
||||
{
|
||||
void **mem = g_local_mp_stdmem ? *g_local_mp_stdmem : NULL;
|
||||
void **vtable;
|
||||
|
||||
if (ptr == NULL || mem == NULL || *mem == NULL)
|
||||
return;
|
||||
vtable = (void **)(*mem);
|
||||
((DagorMemFreeFn)vtable[8])(mem, ptr);
|
||||
}
|
||||
|
||||
char *local_mp_strdup(const char *s)
|
||||
{
|
||||
size_t len;
|
||||
char *copy;
|
||||
|
||||
if (s == NULL || s[0] == '\0')
|
||||
return NULL;
|
||||
len = strlen(s) + 1;
|
||||
copy = (char *)local_mp_mem_alloc(len);
|
||||
if (copy != NULL)
|
||||
memcpy(copy, s, len);
|
||||
return copy;
|
||||
}
|
||||
|
||||
const char *local_mp_unit_name(const uint8_t *unit)
|
||||
{
|
||||
const uint8_t *uinfo;
|
||||
const char *name;
|
||||
|
||||
if (unit == NULL)
|
||||
return NULL;
|
||||
uinfo = *(const uint8_t *const *)(unit + LMP_UNIT_OFF_INFO);
|
||||
if (uinfo == NULL)
|
||||
return NULL;
|
||||
name = *(const char *const *)(uinfo + LMP_UNIT_INFO_OFF_NAME);
|
||||
return (name != NULL && name[0] != '\0') ? name : NULL;
|
||||
}
|
||||
|
||||
static int find_exe_text_section(const uint8_t **out_base, size_t *out_size)
|
||||
{
|
||||
const uint8_t *mod = (const uint8_t *)GetModuleHandleW(NULL);
|
||||
const IMAGE_DOS_HEADER *dos;
|
||||
const IMAGE_NT_HEADERS64 *nt;
|
||||
const IMAGE_SECTION_HEADER *sec;
|
||||
WORD i;
|
||||
|
||||
if (mod == NULL) return 0;
|
||||
dos = (const IMAGE_DOS_HEADER *)mod;
|
||||
if (dos->e_magic != IMAGE_DOS_SIGNATURE) return 0;
|
||||
nt = (const IMAGE_NT_HEADERS64 *)(mod + dos->e_lfanew);
|
||||
if (nt->Signature != IMAGE_NT_SIGNATURE) return 0;
|
||||
sec = IMAGE_FIRST_SECTION(nt);
|
||||
for (i = 0; i < nt->FileHeader.NumberOfSections; i++, sec++) {
|
||||
if (memcmp(sec->Name, ".text\0\0\0", 8) == 0) {
|
||||
*out_base = mod + sec->VirtualAddress;
|
||||
*out_size = sec->Misc.VirtualSize;
|
||||
return 1;
|
||||
}
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static int verify_core_rip_opcodes(
|
||||
const uint8_t *p_refl_dtor,
|
||||
const uint8_t *p_sq_country,
|
||||
const uint8_t *p_get_country
|
||||
)
|
||||
{
|
||||
return p_refl_dtor[0x8b] == 0x48 && p_refl_dtor[0x8c] == 0x8b && p_refl_dtor[0x8d] == 0x0d &&
|
||||
p_sq_country[0x1c] == 0x48 && p_sq_country[0x1d] == 0x8d && p_sq_country[0x1e] == 0x0d &&
|
||||
p_get_country[0x2e] == 0x44 && p_get_country[0x2f] == 0x3b && p_get_country[0x30] == 0x15 &&
|
||||
p_get_country[0x37] == 0x4c && p_get_country[0x38] == 0x8b && p_get_country[0x39] == 0x1d;
|
||||
}
|
||||
|
||||
void install_local_mp_hooks(void)
|
||||
{
|
||||
const uint8_t *text = NULL;
|
||||
size_t text_size = 0;
|
||||
uint8_t *p_disabled_mask, *p_do_respawn, *p_get_country, *p_sq_country, *p_blk_str;
|
||||
uint8_t *p_refl_dtor, *p_change_res, *p_set_gui, *p_unit_eid, *p_set_owner, *p_ground_dead;
|
||||
|
||||
if (!find_exe_text_section(&text, &text_size)) {
|
||||
log_line("local_mp: executable .text section not found, skipping");
|
||||
return;
|
||||
}
|
||||
|
||||
p_disabled_mask = local_mp_scan_unique(text, text_size, "getDisabledSlotsMask", LMP_SIG_DISABLED_SLOTS_MASK);
|
||||
p_do_respawn = local_mp_scan_unique(text, text_size, "doRespawnPlayer", LMP_SIG_DO_RESPAWN_PLAYER);
|
||||
p_get_country = local_mp_scan_unique(text, text_size, "MissionSettings::getPlayerCountry", LMP_SIG_GET_PLAYER_COUNTRY);
|
||||
p_sq_country = local_mp_scan_unique(text, text_size, "sq_get_local_player_country", LMP_SIG_SQ_LOCAL_COUNTRY);
|
||||
p_refl_dtor = local_mp_scan_unique(text, text_size, "ChangeUnitReflection::dtor", LMP_SIG_REFL_DTOR);
|
||||
p_change_res = local_mp_scan_unique(text, text_size, "aircraftChangeResultFromHost", LMP_SIG_AIRCRAFT_CHANGE_RESULT);
|
||||
p_set_gui = local_mp_scan_unique(text, text_size, "setPlayerGuiState", LMP_SIG_SET_PLAYER_GUI_STATE);
|
||||
p_unit_eid = local_mp_scan_unique(text, text_size, "getUnitByEid", LMP_SIG_GET_UNIT_BY_EID);
|
||||
p_set_owner = local_mp_scan_unique(text, text_size, "Unit::setOwningMPlayer", LMP_SIG_SET_OWNING_MPLAYER);
|
||||
p_ground_dead = local_mp_scan_unique(text, text_size, "IGroundModel::onBecameDead", LMP_SIG_IGROUND_ON_DEAD);
|
||||
p_blk_str = local_mp_scan_unique(text, text_size, "DataBlock::getStr", LMP_SIG_DATABLOCK_GET_STR);
|
||||
|
||||
if (!p_disabled_mask || !p_do_respawn || !p_get_country || !p_sq_country || !p_refl_dtor ||
|
||||
!p_change_res || !p_set_gui || !p_unit_eid || !p_set_owner || !p_ground_dead || !p_blk_str ||
|
||||
!verify_core_rip_opcodes(p_refl_dtor, p_sq_country, p_get_country)) {
|
||||
log_line("local_mp: core signatures or RIP layout unavailable, LocalMP bridge disabled");
|
||||
return;
|
||||
}
|
||||
|
||||
g_local_mp_multiplayer = (uint8_t **)local_mp_resolve_rip(p_disabled_mask + 0x02, 3, 8);
|
||||
g_local_mp_app = (uint8_t **)local_mp_resolve_rip(p_disabled_mask + 0x0c, 3, 7);
|
||||
g_local_mp_mplayer = (uint8_t **)local_mp_resolve_rip(p_disabled_mask + 0x1f, 3, 7);
|
||||
g_local_mp_hero = (uint8_t **)local_mp_resolve_rip(p_do_respawn + 0x7d, 3, 7);
|
||||
g_local_mp_mission_settings = (uint8_t *)local_mp_resolve_rip(p_sq_country + 0x1c, 3, 7);
|
||||
g_local_mp_stdmem = (void ***)local_mp_resolve_rip(p_refl_dtor + 0x8b, 3, 7);
|
||||
g_local_mp_player_count = (uint32_t *)local_mp_resolve_rip(p_get_country + 0x2e, 3, 7);
|
||||
g_local_mp_player_table = (uint8_t ***)local_mp_resolve_rip(p_get_country + 0x37, 3, 7);
|
||||
|
||||
g_lmp_get_player_country = (LmpGetPlayerCountryFn)p_get_country;
|
||||
g_lmp_set_player_gui_state = (LmpSetPlayerGuiStateFn)p_set_gui;
|
||||
g_lmp_aircraft_change_result = (LmpAircraftChangeResultFn)p_change_res;
|
||||
g_lmp_get_unit_by_eid = (LmpGetUnitByEidFn)p_unit_eid;
|
||||
g_lmp_set_owning_mplayer = (LmpSetOwningMPlayerFn)p_set_owner;
|
||||
g_lmp_datablock_get_str = (LmpDataBlockGetStrFn)p_blk_str;
|
||||
|
||||
if (!install_local_mp_player_hooks(text, text_size, p_do_respawn) ||
|
||||
!install_local_mp_loadout_hooks(text, text_size) ||
|
||||
!install_local_mp_action_hooks(text, text_size) ||
|
||||
!install_local_mp_ledger_hooks(text, text_size, p_ground_dead) ||
|
||||
!install_local_mp_kill_hooks(text, text_size, p_ground_dead) ||
|
||||
!install_local_mp_event_hooks(text, text_size)) {
|
||||
log_line("local_mp: one or more LocalMP subsystem hooks failed to initialize");
|
||||
return;
|
||||
}
|
||||
log_line("local_mp: all LocalMP host subsystems installed");
|
||||
}
|
||||
@@ -0,0 +1,284 @@
|
||||
/*
|
||||
* LocalMP non-fatal combat event dispatchers: deduplicated assists across air/ground/naval,
|
||||
* zone captures, hits/criticals, severe damage, and naval damage awards.
|
||||
*
|
||||
* `IGroundModel::onBecameDead` calls both `IGroundModel::awardAssists` (`0x465540`) and
|
||||
* `Unit::awardAssists` (`0xe5b200` -> `dispatchAssist` `0x35beb0`); deduplicating `(victim, mp)`
|
||||
* per unit death ensures every assist across air, ground, and naval is credited strictly once.
|
||||
*/
|
||||
#include "hooks.h"
|
||||
#include "hook_config.h"
|
||||
#include "local_mp_internal.h"
|
||||
#include "local_mp_offsets.h"
|
||||
|
||||
#include "MinHook.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define SCORE_SEVERE_DAMAGE 160.0f
|
||||
#define SCORE_PVP_ASSIST 100.0f
|
||||
#define SCORE_AI_UNIT_ASSIST 30.0f
|
||||
#define SCORE_CAPTURE_ZONE 300.0f
|
||||
#define SCORE_CRITICAL_HIT 50.0f
|
||||
#define SCORE_HIT 10.0f
|
||||
#define SCORE_NAVAL_DMG_FACTOR 0.08f
|
||||
#define MAX_OFFENDER_SNAP 64u
|
||||
#define MAX_ASSIST_DEDUP 64u
|
||||
|
||||
#define HUD_MSG_HIT_FEED 3u
|
||||
#define HUD_MSG_CENTER_BANNER 4u
|
||||
|
||||
typedef struct AssistDedupRecord {
|
||||
const uint8_t *victim;
|
||||
const uint8_t *offender_mp;
|
||||
} AssistDedupRecord;
|
||||
|
||||
typedef void (__fastcall *IGroundAwardAssistsFn)(uint8_t *victim);
|
||||
typedef void (__fastcall *DispatchAssistFn)(int64_t uid, uint8_t *victim, uint8_t *offender, float share, int32_t extra);
|
||||
typedef void (__fastcall *DispatchCaptureZoneFn)(int64_t uid, uint8_t *capturer_unit);
|
||||
typedef void (__fastcall *DispatchHitCritFn)(int64_t uid, uint8_t *victim, uint8_t *offender, float dmg, uint8_t is_kill, uint8_t is_crit, uint8_t extra);
|
||||
typedef void (__fastcall *DispatchSevereDamageFn)(int64_t uid, uint8_t *victim, uint8_t *offender);
|
||||
typedef void (__fastcall *DispatchNavalDamageFn)(int64_t uid, uint8_t *victim, uint8_t *offender, float award_dmg);
|
||||
|
||||
static IGroundAwardAssistsFn orig_iground_award_assists;
|
||||
static DispatchAssistFn orig_dispatch_assist;
|
||||
static DispatchCaptureZoneFn orig_dispatch_capture_zone;
|
||||
static DispatchHitCritFn orig_dispatch_hit_crit;
|
||||
static DispatchSevereDamageFn orig_dispatch_severe_damage;
|
||||
static DispatchNavalDamageFn orig_dispatch_naval_damage;
|
||||
|
||||
static AssistDedupRecord g_assist_dedup[MAX_ASSIST_DEDUP];
|
||||
static size_t g_assist_dedup_cursor = 0;
|
||||
|
||||
void local_mp_events_reset(void)
|
||||
{
|
||||
memset(g_assist_dedup, 0, sizeof(g_assist_dedup));
|
||||
g_assist_dedup_cursor = 0;
|
||||
}
|
||||
|
||||
void local_mp_events_begin_death(const uint8_t *victim)
|
||||
{
|
||||
size_t i;
|
||||
if (victim == NULL)
|
||||
return;
|
||||
for (i = 0; i < MAX_ASSIST_DEDUP; i++) {
|
||||
if (g_assist_dedup[i].victim == victim) {
|
||||
g_assist_dedup[i].victim = NULL;
|
||||
g_assist_dedup[i].offender_mp = NULL;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int mark_assist_credited_once(const uint8_t *victim, const uint8_t *mp)
|
||||
{
|
||||
size_t i;
|
||||
for (i = 0; i < MAX_ASSIST_DEDUP; i++) {
|
||||
if (g_assist_dedup[i].victim == victim && g_assist_dedup[i].offender_mp == mp)
|
||||
return 0;
|
||||
}
|
||||
g_assist_dedup[g_assist_dedup_cursor].victim = victim;
|
||||
g_assist_dedup[g_assist_dedup_cursor].offender_mp = mp;
|
||||
g_assist_dedup_cursor = (g_assist_dedup_cursor + 1u) % MAX_ASSIST_DEDUP;
|
||||
return 1;
|
||||
}
|
||||
|
||||
static void credit_assist_to_mplayer(uint8_t *mp, uint8_t *victim)
|
||||
{
|
||||
uint8_t *victim_mp = *(uint8_t **)(victim + LMP_UNIT_OFF_MPLAYER);
|
||||
float pts;
|
||||
|
||||
if (mp == NULL || mp == victim_mp || !mark_assist_credited_once(victim, mp))
|
||||
return;
|
||||
pts = victim_mp ? SCORE_PVP_ASSIST : SCORE_AI_UNIT_ASSIST;
|
||||
local_mp_inc_mplayer_stat(mp, LMP_MP_OFF_ASSISTS);
|
||||
local_mp_add_mplayer_score(mp, pts, LMP_EXP_EVENT_ASSIST);
|
||||
local_mp_mark_mplayer_dirty(mp);
|
||||
if (local_mp_is_local_mplayer(mp)) {
|
||||
const char *uname = local_mp_active_player_unit_name();
|
||||
const LocalMpUnitRates *rates = local_mp_ledger_rates_for_unit(uname);
|
||||
float mul = victim_mp ? 0.45f : (0.45f * rates->ai_kill_k);
|
||||
int32_t wp = (int32_t)(rates->wp_per_kill * mul + 0.5f);
|
||||
int32_t rp = (int32_t)(180.0f * rates->exp_mul * mul + 0.5f);
|
||||
local_mp_ledger_record_event(uname, LMP_STAT_BKT_ASSIST, 1, wp, rp, pts);
|
||||
local_mp_ledger_banner(LMP_EXP_EVENT_ASSIST, HUD_MSG_CENTER_BANNER, rp, wp, victim);
|
||||
}
|
||||
}
|
||||
|
||||
static void __fastcall hook_iground_award_assists(uint8_t *victim)
|
||||
{
|
||||
uint8_t prev_sent[MAX_OFFENDER_SNAP];
|
||||
uint32_t count = 0;
|
||||
uint8_t *arr = NULL;
|
||||
uint32_t i;
|
||||
|
||||
if (local_mp_is_host() && victim != NULL) {
|
||||
arr = *(uint8_t **)(victim + LMP_IGM_OFF_OFFENDERS_PTR);
|
||||
count = *(uint32_t *)(victim + LMP_IGM_OFF_OFFENDERS_CNT);
|
||||
if (count > MAX_OFFENDER_SNAP)
|
||||
count = MAX_OFFENDER_SNAP;
|
||||
for (i = 0; arr != NULL && i < count; i++)
|
||||
prev_sent[i] = arr[i * LMP_OFFENDER_STRIDE + LMP_OFFENDER_OFF_ASSIST_SENT];
|
||||
}
|
||||
|
||||
orig_iground_award_assists(victim);
|
||||
|
||||
if (local_mp_is_host() && victim != NULL && arr != NULL && count > 0) {
|
||||
arr = *(uint8_t **)(victim + LMP_IGM_OFF_OFFENDERS_PTR);
|
||||
for (i = 0; arr != NULL && i < count; i++) {
|
||||
uint8_t *off = arr + i * LMP_OFFENDER_STRIDE;
|
||||
if (prev_sent[i] == 0 && off[LMP_OFFENDER_OFF_ASSIST_SENT] != 0) {
|
||||
uint8_t *mp = local_mp_find_mplayer(
|
||||
*(int64_t *)(off + LMP_OFFENDER_OFF_UID), off[LMP_OFFENDER_OFF_PID]);
|
||||
credit_assist_to_mplayer(mp, victim);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void __fastcall hook_dispatch_assist(int64_t uid, uint8_t *victim, uint8_t *offender, float share, int32_t extra)
|
||||
{
|
||||
if (local_mp_is_host() && victim != NULL) {
|
||||
uint8_t *mp = local_mp_find_mplayer(uid, offender ? offender[LMP_OFFENDER_OFF_PID] : 0xffu);
|
||||
credit_assist_to_mplayer(mp, victim);
|
||||
}
|
||||
orig_dispatch_assist(uid, victim, offender, share, extra);
|
||||
}
|
||||
|
||||
static void __fastcall hook_dispatch_capture_zone(int64_t uid, uint8_t *capturer_unit)
|
||||
{
|
||||
if (local_mp_is_host()) {
|
||||
uint8_t *mp = local_mp_find_mplayer(uid, 0xffu);
|
||||
if (mp == NULL && capturer_unit != NULL)
|
||||
mp = *(uint8_t **)(capturer_unit + LMP_UNIT_OFF_MPLAYER);
|
||||
if (mp != NULL) {
|
||||
local_mp_inc_mplayer_stat(mp, LMP_MP_OFF_CAPTURE_ZONE);
|
||||
local_mp_add_mplayer_score(mp, SCORE_CAPTURE_ZONE, LMP_EXP_EVENT_CAPTURE_ZONE);
|
||||
local_mp_mark_mplayer_dirty(mp);
|
||||
if (local_mp_is_local_mplayer(mp)) {
|
||||
const char *uname = capturer_unit ? local_mp_unit_name(capturer_unit) : NULL;
|
||||
const LocalMpUnitRates *rates = local_mp_ledger_rates_for_unit(uname);
|
||||
int32_t wp = (int32_t)(rates->wp_per_kill + 0.5f);
|
||||
int32_t rp = (int32_t)(200.0f * rates->exp_mul + 0.5f);
|
||||
local_mp_ledger_record_event(uname, LMP_STAT_BKT_CAPTURES, 1, wp, rp, SCORE_CAPTURE_ZONE);
|
||||
local_mp_ledger_banner(LMP_EXP_EVENT_CAPTURE_ZONE, HUD_MSG_CENTER_BANNER, rp, wp, capturer_unit);
|
||||
}
|
||||
}
|
||||
}
|
||||
orig_dispatch_capture_zone(uid, capturer_unit);
|
||||
}
|
||||
|
||||
static void __fastcall hook_dispatch_hit_crit(
|
||||
int64_t uid, uint8_t *victim, uint8_t *offender, float dmg, uint8_t is_kill, uint8_t is_crit, uint8_t extra
|
||||
)
|
||||
{
|
||||
if (local_mp_is_host() && !is_kill && victim != NULL) {
|
||||
uint8_t *mp = local_mp_find_mplayer(uid, offender ? offender[LMP_OFFENDER_OFF_PID] : 0xffu);
|
||||
if (mp != NULL && mp != *(uint8_t **)(victim + LMP_UNIT_OFF_MPLAYER)) {
|
||||
float pts = is_crit ? SCORE_CRITICAL_HIT : SCORE_HIT;
|
||||
uint32_t ev = is_crit ? LMP_EXP_EVENT_CRITICAL_HIT : LMP_EXP_EVENT_HIT;
|
||||
local_mp_add_mplayer_score(mp, pts, ev);
|
||||
local_mp_mark_mplayer_dirty(mp);
|
||||
if (local_mp_is_local_mplayer(mp)) {
|
||||
const char *uname = local_mp_active_player_unit_name();
|
||||
const LocalMpUnitRates *rates = local_mp_ledger_rates_for_unit(uname);
|
||||
float mul = is_crit ? 0.20f : 0.06f;
|
||||
int32_t wp = (int32_t)(rates->wp_per_kill * mul + 0.5f);
|
||||
int32_t rp = (int32_t)(180.0f * rates->exp_mul * mul + 0.5f);
|
||||
local_mp_ledger_record_event(uname, is_crit ? LMP_STAT_BKT_CRITICAL : LMP_STAT_BKT_HIT, 1, wp, rp, pts);
|
||||
local_mp_ledger_banner(ev, HUD_MSG_HIT_FEED, rp, wp, victim);
|
||||
}
|
||||
}
|
||||
}
|
||||
orig_dispatch_hit_crit(uid, victim, offender, dmg, is_kill, is_crit, extra);
|
||||
}
|
||||
|
||||
static void __fastcall hook_dispatch_severe_damage(int64_t uid, uint8_t *victim, uint8_t *offender)
|
||||
{
|
||||
if (local_mp_is_host() && victim != NULL && offender != NULL) {
|
||||
uint8_t victim_army = victim[LMP_UNIT_OFF_ARMY];
|
||||
if (victim_army == 0 || *(int32_t *)(offender + LMP_OFFENDER_OFF_ARMY) != (int32_t)victim_army) {
|
||||
uint8_t *mp = local_mp_find_mplayer(uid, offender[LMP_OFFENDER_OFF_PID]);
|
||||
uint8_t *victim_mp = *(uint8_t **)(victim + LMP_UNIT_OFF_MPLAYER);
|
||||
if (mp != NULL && mp != victim_mp && victim_mp != NULL) {
|
||||
uint16_t utype = *(uint16_t *)(victim + LMP_UNIT_OFF_TYPE);
|
||||
int is_air = (utype == 0u || utype == 0xdu);
|
||||
if (is_air) local_mp_inc_mplayer_stat(mp, LMP_MP_OFF_AIR_SEVERE_DMG);
|
||||
else if (utype == 5u) local_mp_inc_mplayer_stat(mp, LMP_MP_OFF_SHIP_SEVERE_DMG);
|
||||
local_mp_add_mplayer_score(mp, SCORE_SEVERE_DAMAGE, LMP_EXP_EVENT_SEVERE_DAMAGE);
|
||||
local_mp_mark_mplayer_dirty(mp);
|
||||
if (local_mp_is_local_mplayer(mp)) {
|
||||
const char *uname = local_mp_active_player_unit_name();
|
||||
const LocalMpUnitRates *rates = local_mp_ledger_rates_for_unit(uname);
|
||||
int32_t wp = (int32_t)(rates->wp_per_kill * 0.8f + 0.5f);
|
||||
int32_t rp = (int32_t)(144.0f * rates->exp_mul + 0.5f);
|
||||
local_mp_ledger_record_event(uname, is_air ? LMP_STAT_BKT_AIR_SEVERE : LMP_STAT_BKT_SHIP_SEVERE, 1, wp, rp, SCORE_SEVERE_DAMAGE);
|
||||
local_mp_ledger_banner(LMP_EXP_EVENT_SEVERE_DAMAGE, HUD_MSG_CENTER_BANNER, rp, wp, victim);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
orig_dispatch_severe_damage(uid, victim, offender);
|
||||
}
|
||||
|
||||
static void __fastcall hook_dispatch_naval_damage(int64_t uid, uint8_t *victim, uint8_t *offender, float award_dmg)
|
||||
{
|
||||
if (local_mp_is_host() && victim != NULL && offender != NULL && award_dmg > 0.0f) {
|
||||
uint8_t victim_army = victim[LMP_UNIT_OFF_ARMY];
|
||||
if (victim_army == 0 || *(int32_t *)(offender + LMP_OFFENDER_OFF_ARMY) != (int32_t)victim_army) {
|
||||
uint8_t *mp = local_mp_find_mplayer(uid, offender[LMP_OFFENDER_OFF_PID]);
|
||||
if (mp != NULL) {
|
||||
int32_t add_dmg = (int32_t)(award_dmg + 0.5f);
|
||||
float pts = award_dmg * SCORE_NAVAL_DMG_FACTOR;
|
||||
if (add_dmg > 0) *(int32_t *)(mp + LMP_MP_OFF_AWARD_DAMAGE) += add_dmg;
|
||||
if (pts >= 1.0f) local_mp_add_mplayer_score(mp, pts, LMP_EXP_EVENT_UNIT_DAMAGE);
|
||||
local_mp_mark_mplayer_dirty(mp);
|
||||
if (local_mp_is_local_mplayer(mp) && add_dmg > 0) {
|
||||
const char *uname = local_mp_active_player_unit_name();
|
||||
const LocalMpUnitRates *rates = local_mp_ledger_rates_for_unit(uname);
|
||||
int32_t wp = (int32_t)(rates->wp_per_kill * (award_dmg / 1500.0f) + 0.5f);
|
||||
int32_t rp = (int32_t)(rates->exp_mul * (award_dmg * 0.10f) + 0.5f);
|
||||
local_mp_ledger_record_event(uname, LMP_STAT_BKT_AWARD_DAMAGE, add_dmg, wp, rp, pts >= 1.0f ? pts : 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
orig_dispatch_naval_damage(uid, victim, offender, award_dmg);
|
||||
}
|
||||
|
||||
int install_local_mp_event_hooks(const uint8_t *text, size_t text_size)
|
||||
{
|
||||
uint8_t *p_igm_ass = local_mp_scan_unique(text, text_size, "IGroundModel::awardAssists", LMP_SIG_IGROUND_AWARD_ASSISTS);
|
||||
uint8_t *p_assist = local_mp_scan_unique(text, text_size, "dispatchAssist", LMP_SIG_DISPATCH_ASSIST);
|
||||
uint8_t *p_cap_c = local_mp_scan_unique(text, text_size, "caller_captureZone", LMP_SIG_CALLER_CAPTURE_ZONE);
|
||||
uint8_t *p_hit_c = local_mp_scan_unique(text, text_size, "caller_hitCrit", LMP_SIG_CALLER_HIT_CRIT);
|
||||
uint8_t *p_sev_c = local_mp_scan_unique(text, text_size, "caller_severeDmg", LMP_SIG_CALLER_SEVERE_DMG);
|
||||
uint8_t *p_nav_c = local_mp_scan_unique(text, text_size, "caller_navalDmg", LMP_SIG_CALLER_NAVAL_DMG);
|
||||
uint8_t *p_cap, *p_hit, *p_sev, *p_nav;
|
||||
|
||||
if (!p_igm_ass || !p_assist || !p_cap_c || !p_hit_c || !p_sev_c || !p_nav_c)
|
||||
return 0;
|
||||
if (p_cap_c[0x6b] != 0xe8 || p_hit_c[0x59] != 0xe8 || p_sev_c[0x2f] != 0xe8 || p_nav_c[0x67] != 0xe8)
|
||||
return 0;
|
||||
|
||||
p_cap = (uint8_t *)local_mp_resolve_rip(p_cap_c + 0x6b, 1, 5);
|
||||
p_hit = (uint8_t *)local_mp_resolve_rip(p_hit_c + 0x59, 1, 5);
|
||||
p_sev = (uint8_t *)local_mp_resolve_rip(p_sev_c + 0x2f, 1, 5);
|
||||
p_nav = (uint8_t *)local_mp_resolve_rip(p_nav_c + 0x67, 1, 5);
|
||||
|
||||
if (MH_CreateHook(p_igm_ass, (void *)&hook_iground_award_assists, (void **)&orig_iground_award_assists) != MH_OK ||
|
||||
MH_EnableHook(p_igm_ass) != MH_OK ||
|
||||
MH_CreateHook(p_assist, (void *)&hook_dispatch_assist, (void **)&orig_dispatch_assist) != MH_OK ||
|
||||
MH_EnableHook(p_assist) != MH_OK ||
|
||||
MH_CreateHook(p_cap, (void *)&hook_dispatch_capture_zone, (void **)&orig_dispatch_capture_zone) != MH_OK ||
|
||||
MH_EnableHook(p_cap) != MH_OK ||
|
||||
MH_CreateHook(p_hit, (void *)&hook_dispatch_hit_crit, (void **)&orig_dispatch_hit_crit) != MH_OK ||
|
||||
MH_EnableHook(p_hit) != MH_OK ||
|
||||
MH_CreateHook(p_sev, (void *)&hook_dispatch_severe_damage, (void **)&orig_dispatch_severe_damage) != MH_OK ||
|
||||
MH_EnableHook(p_sev) != MH_OK ||
|
||||
MH_CreateHook(p_nav, (void *)&hook_dispatch_naval_damage, (void **)&orig_dispatch_naval_damage) != MH_OK ||
|
||||
MH_EnableHook(p_nav) != MH_OK) {
|
||||
log_line("local_mp: failed to install combat event hooks");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,103 @@
|
||||
/*
|
||||
* Shared internal state, resolved engine pointers, and subsystem interfaces
|
||||
* for the LocalMP in-process host bridge.
|
||||
*
|
||||
* All addresses are resolved dynamically from masked .text signatures in
|
||||
* local_mp_offsets.h and every detour is gated on local_mp_is_host().
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#include <stddef.h>
|
||||
#include <stdint.h>
|
||||
|
||||
#define LMP_MAX_UNIT_RATES 32u
|
||||
|
||||
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);
|
||||
|
||||
typedef struct LocalMpUnitRates {
|
||||
char unit_name[64];
|
||||
float wp_per_kill;
|
||||
float exp_mul;
|
||||
float battle_time_award;
|
||||
float ai_kill_k;
|
||||
float win_k;
|
||||
} LocalMpUnitRates;
|
||||
|
||||
typedef struct LocalMpUnitRateEntry {
|
||||
LocalMpUnitRates rates;
|
||||
uint8_t spawned;
|
||||
} LocalMpUnitRateEntry;
|
||||
|
||||
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;
|
||||
|
||||
uint8_t *local_mp_scan_unique(const uint8_t *base, size_t size, const char *name, const char *spec);
|
||||
void *local_mp_resolve_rip(const uint8_t *insn, size_t disp_off, size_t insn_len);
|
||||
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);
|
||||
const char *local_mp_active_player_unit_name(void);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* SessionStatsNet ledger & HUD center-screen reward banner API. */
|
||||
void local_mp_ledger_reset(void);
|
||||
void local_mp_ledger_store_rates(const LocalMpUnitRates *rates);
|
||||
void local_mp_ledger_activate_unit(const char *unit_name);
|
||||
const LocalMpUnitRates *local_mp_ledger_rates_for_unit(const char *unit_name);
|
||||
void local_mp_ledger_record_event(
|
||||
const char *unit_name,
|
||||
size_t bucket_off,
|
||||
int32_t count_inc,
|
||||
int32_t wp,
|
||||
int32_t exp,
|
||||
float score_delta
|
||||
);
|
||||
void local_mp_ledger_banner(
|
||||
uint32_t event_id,
|
||||
uint32_t msg_type,
|
||||
int32_t xp,
|
||||
int32_t wp,
|
||||
void *target_unit
|
||||
);
|
||||
|
||||
/* 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);
|
||||
|
||||
/* Subsystem hook installers invoked once from install_local_mp_hooks(). */
|
||||
int install_local_mp_player_hooks(const uint8_t *text, size_t text_size, uint8_t *p_do_respawn);
|
||||
int install_local_mp_loadout_hooks(const uint8_t *text, size_t text_size);
|
||||
int install_local_mp_action_hooks(const uint8_t *text, size_t text_size);
|
||||
int install_local_mp_ledger_hooks(const uint8_t *text, size_t text_size, uint8_t *p_ground_dead);
|
||||
int install_local_mp_kill_hooks(const uint8_t *text, size_t text_size, uint8_t *p_ground_dead);
|
||||
int install_local_mp_event_hooks(const uint8_t *text, size_t text_size);
|
||||
@@ -0,0 +1,213 @@
|
||||
/*
|
||||
* LocalMP authoritative unit-death and kill-attribution hooks across all vehicle branches.
|
||||
*
|
||||
* Hooks BOTH `IGroundModel::onBecameDead` (tanks, IFVs, SPAA, boats, ships, infantry)
|
||||
* and `onUnitDeadOnce` (aircraft & helicopters). All 31 bound MPlayer bots receive 1:1
|
||||
* PvP kill/death counters and battle score alongside the local player.
|
||||
*/
|
||||
#include "hooks.h"
|
||||
#include "hook_config.h"
|
||||
#include "local_mp_internal.h"
|
||||
#include "local_mp_offsets.h"
|
||||
|
||||
#include "MinHook.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define SCORE_PVP_KILL 200.0f
|
||||
#define SCORE_SEVERE_FINISH 40.0f
|
||||
#define SCORE_AI_UNIT_KILL 60.0f
|
||||
#define SCORE_DEATH 30.0f
|
||||
#define HUD_MSG_CENTER_BANNER 4u
|
||||
|
||||
typedef void (__fastcall *MPlayerAddScoreFn)(uint8_t *mp, float delta, uint32_t event_id, uint8_t add_team);
|
||||
typedef void (__fastcall *NetMarkDirtyFn)(void *dirty_field, void *owner_obj, void *payload_ptr);
|
||||
typedef void (__fastcall *ChooseOffenderVfn)(uint8_t *victim, uint8_t *out_offender, uint8_t clear_flag);
|
||||
typedef void (__fastcall *IGroundOnDeadFn)(uint8_t *victim, int32_t p2);
|
||||
typedef void (__fastcall *OnUnitDeadOnceFn)(uint8_t *victim);
|
||||
|
||||
static MPlayerAddScoreFn fn_mplayer_add_score;
|
||||
static NetMarkDirtyFn fn_net_mark_dirty;
|
||||
static IGroundOnDeadFn orig_iground_on_dead;
|
||||
static OnUnitDeadOnceFn orig_on_unit_dead_once;
|
||||
|
||||
void local_mp_mark_mplayer_dirty(uint8_t *mp)
|
||||
{
|
||||
if (mp != NULL && fn_net_mark_dirty != NULL)
|
||||
fn_net_mark_dirty(mp + LMP_MP_OFF_STAT_DIRTY, mp, mp + LMP_MP_OFF_STAT_PAYLOAD);
|
||||
}
|
||||
|
||||
void local_mp_inc_mplayer_stat(uint8_t *mp, size_t off)
|
||||
{
|
||||
int16_t v = *(int16_t *)(mp + off);
|
||||
if (v < 32767)
|
||||
*(int16_t *)(mp + off) = (int16_t)(v + 1);
|
||||
}
|
||||
|
||||
static void dec_mplayer_stat_pos(uint8_t *mp, size_t off)
|
||||
{
|
||||
int16_t v = *(int16_t *)(mp + off);
|
||||
if (v > 0)
|
||||
*(int16_t *)(mp + off) = (int16_t)(v - 1);
|
||||
}
|
||||
|
||||
void local_mp_add_mplayer_score(uint8_t *mp, float delta, uint32_t event_id)
|
||||
{
|
||||
uint8_t *app = g_local_mp_app ? *g_local_mp_app : NULL;
|
||||
int32_t total;
|
||||
if (mp == NULL || delta <= 0.0f || event_id >= LMP_EXP_EVENT_COUNT || !fn_mplayer_add_score)
|
||||
return;
|
||||
if (app == NULL || *(void **)(app + LMP_APP_OFF_SCORE_RULES) == NULL)
|
||||
return;
|
||||
fn_mplayer_add_score(mp, delta, event_id, 1);
|
||||
total = *(int32_t *)(mp + LMP_MP_OFF_SCORE);
|
||||
*(int16_t *)(mp + LMP_MP_OFF_FALLBACK_SCORE) = (total > 32767) ? (int16_t)32767 : (int16_t)total;
|
||||
}
|
||||
|
||||
static int is_same_severe_offender(const uint8_t *victim, const uint8_t *killer_mp)
|
||||
{
|
||||
if (victim == NULL || killer_mp == NULL || *(const int16_t *)(victim + LMP_UNIT_OFF_SEVERE_IDX) == -1)
|
||||
return 0;
|
||||
return local_mp_find_mplayer(*(const int64_t *)(victim + LMP_UNIT_OFF_SEVERE_UID),
|
||||
victim[LMP_UNIT_OFF_SEVERE_PID]) == killer_mp;
|
||||
}
|
||||
|
||||
static void record_enemy_kill(uint8_t *killer_mp, uint8_t *victim, int is_pvp)
|
||||
{
|
||||
uint16_t utype = *(uint16_t *)(victim + LMP_UNIT_OFF_TYPE);
|
||||
int is_air = (utype == 0u || utype == 0xdu);
|
||||
int is_ship = (utype == 5u);
|
||||
int is_human = (utype == 0xeu);
|
||||
int own_sev = is_pvp && (is_air || is_ship) && is_same_severe_offender(victim, killer_mp);
|
||||
uint32_t ev = is_air ? LMP_EXP_EVENT_KILL : (is_human ? LMP_EXP_EVENT_KILL_HUMAN : LMP_EXP_EVENT_KILL_GROUND);
|
||||
size_t bkt = is_air ? LMP_STAT_BKT_AIR_KILLS : (is_ship ? LMP_STAT_BKT_NAVAL_KILLS :
|
||||
(is_human ? LMP_STAT_BKT_HUMAN_KILLS : LMP_STAT_BKT_GROUND_KILLS));
|
||||
float pts = is_pvp ? (own_sev ? SCORE_SEVERE_FINISH : SCORE_PVP_KILL) : SCORE_AI_UNIT_KILL;
|
||||
|
||||
if (is_pvp) {
|
||||
local_mp_inc_mplayer_stat(killer_mp, is_air ? LMP_MP_OFF_KILLS : (is_ship ? LMP_MP_OFF_NAVAL_KILLS :
|
||||
(is_human ? LMP_MP_OFF_HUMAN_KILLS : LMP_MP_OFF_GROUND_KILLS)));
|
||||
if (own_sev)
|
||||
dec_mplayer_stat_pos(killer_mp, is_air ? LMP_MP_OFF_AIR_SEVERE_DMG : LMP_MP_OFF_SHIP_SEVERE_DMG);
|
||||
} else {
|
||||
local_mp_inc_mplayer_stat(killer_mp, is_air ? LMP_MP_OFF_AI_KILLS :
|
||||
(is_ship ? LMP_MP_OFF_AI_NAVAL_KILLS : LMP_MP_OFF_AI_GROUND_KILLS));
|
||||
}
|
||||
local_mp_add_mplayer_score(killer_mp, pts, ev);
|
||||
local_mp_mark_mplayer_dirty(killer_mp);
|
||||
|
||||
if (local_mp_is_local_mplayer(killer_mp)) {
|
||||
const char *uname = local_mp_active_player_unit_name();
|
||||
const LocalMpUnitRates *rates = local_mp_ledger_rates_for_unit(uname);
|
||||
float mul = is_pvp ? (own_sev ? 0.2f : 1.0f) : rates->ai_kill_k;
|
||||
int32_t wp = (int32_t)(rates->wp_per_kill * mul + 0.5f);
|
||||
int32_t rp = (int32_t)(180.0f * rates->exp_mul * mul + 0.5f);
|
||||
local_mp_ledger_record_event(uname, bkt, 1, wp, rp, pts);
|
||||
local_mp_ledger_banner(ev, HUD_MSG_CENTER_BANNER, rp, wp, victim);
|
||||
}
|
||||
}
|
||||
|
||||
static void process_unit_death(uint8_t *victim, uint8_t *killer_mp, int32_t killer_army, int allow_kill_credit)
|
||||
{
|
||||
uint8_t *victim_mp = *(uint8_t **)(victim + LMP_UNIT_OFF_MPLAYER);
|
||||
uint8_t victim_army = victim[LMP_UNIT_OFF_ARMY];
|
||||
|
||||
if (victim_mp != NULL) {
|
||||
local_mp_inc_mplayer_stat(victim_mp, LMP_MP_OFF_DEATHS);
|
||||
local_mp_add_mplayer_score(victim_mp, SCORE_DEATH, LMP_EXP_EVENT_DEATH);
|
||||
local_mp_mark_mplayer_dirty(victim_mp);
|
||||
}
|
||||
if (!allow_kill_credit || killer_mp == NULL || killer_mp == victim_mp)
|
||||
return;
|
||||
if (killer_army <= 0)
|
||||
killer_army = (int32_t)killer_mp[LMP_MP_OFF_TEAM];
|
||||
if (victim_army != 0 && killer_army == (int32_t)victim_army) {
|
||||
local_mp_inc_mplayer_stat(killer_mp, LMP_MP_OFF_TEAM_KILLS);
|
||||
local_mp_mark_mplayer_dirty(killer_mp);
|
||||
} else {
|
||||
record_enemy_kill(killer_mp, victim, victim_mp != NULL);
|
||||
}
|
||||
}
|
||||
|
||||
static uint8_t *resolve_offender_killer(uint8_t *victim, int32_t *out_army)
|
||||
{
|
||||
__declspec(align(16)) uint8_t offender[0x180];
|
||||
uintptr_t vtbl = victim ? *(uintptr_t *)victim : 0;
|
||||
ChooseOffenderVfn choose_fn;
|
||||
|
||||
if (vtbl == 0)
|
||||
return NULL;
|
||||
memset(offender, 0, sizeof(offender));
|
||||
*(int16_t *)offender = -1;
|
||||
offender[LMP_OFFENDER_OFF_PID] = 0xffu;
|
||||
*(int64_t *)(offender + LMP_OFFENDER_OFF_UID) = -1;
|
||||
choose_fn = *(ChooseOffenderVfn *)(vtbl + LMP_UNIT_VTF_CHOOSE_OFFENDER);
|
||||
if (choose_fn != NULL)
|
||||
choose_fn(victim, offender, 0);
|
||||
if (*(int16_t *)offender == -1)
|
||||
return NULL;
|
||||
*out_army = *(int32_t *)(offender + LMP_OFFENDER_OFF_ARMY);
|
||||
return local_mp_find_mplayer(*(int64_t *)(offender + LMP_OFFENDER_OFF_UID), offender[LMP_OFFENDER_OFF_PID]);
|
||||
}
|
||||
|
||||
static void __fastcall hook_iground_on_became_dead(uint8_t *victim, int32_t p2)
|
||||
{
|
||||
int is_host = local_mp_is_host();
|
||||
if (is_host && victim != NULL &&
|
||||
victim[LMP_IGM_OFF_ALREADY_DEAD] == 0 &&
|
||||
victim[LMP_IGM_OFF_DEAD_SILENT] == 0) {
|
||||
int allow_kill = (victim[LMP_IGM_OFF_BAILOUT_DEAD] == 0);
|
||||
int32_t killer_army = *(int32_t *)(victim + LMP_IGM_OFF_KILLER_ARMY);
|
||||
uint8_t *killer_mp = allow_kill ? local_mp_find_mplayer(
|
||||
*(int64_t *)(victim + LMP_IGM_OFF_KILLER_UID), victim[LMP_IGM_OFF_KILLER_PID]) : NULL;
|
||||
local_mp_events_begin_death(victim);
|
||||
if (allow_kill && killer_mp == NULL)
|
||||
killer_mp = resolve_offender_killer(victim, &killer_army);
|
||||
if (allow_kill && killer_mp != NULL && victim[LMP_IGM_OFF_KILLER_PID] == 0xffu) {
|
||||
victim[LMP_IGM_OFF_KILLER_PID] = killer_mp[LMP_MP_OFF_PID];
|
||||
*(int64_t *)(victim + LMP_IGM_OFF_KILLER_UID) = *(int64_t *)(killer_mp + LMP_MP_OFF_USER_ID);
|
||||
}
|
||||
process_unit_death(victim, killer_mp, killer_army, allow_kill);
|
||||
}
|
||||
if (is_host && *g_local_mp_multiplayer != NULL) {
|
||||
(*g_local_mp_multiplayer)[LMP_MP_MGR_OFF_IS_LOCAL_MP] = 0;
|
||||
orig_iground_on_dead(victim, p2);
|
||||
if (*g_local_mp_multiplayer != NULL)
|
||||
(*g_local_mp_multiplayer)[LMP_MP_MGR_OFF_IS_LOCAL_MP] = 1;
|
||||
return;
|
||||
}
|
||||
orig_iground_on_dead(victim, p2);
|
||||
}
|
||||
|
||||
static void __fastcall hook_on_unit_dead_once(uint8_t *victim)
|
||||
{
|
||||
if (local_mp_is_host() && victim != NULL && victim[LMP_UNIT_OFF_SKIP_KILL] == 0) {
|
||||
int32_t killer_army = 0;
|
||||
uint8_t *killer_mp = resolve_offender_killer(victim, &killer_army);
|
||||
local_mp_events_begin_death(victim);
|
||||
process_unit_death(victim, killer_mp, killer_army, 1);
|
||||
}
|
||||
orig_on_unit_dead_once(victim);
|
||||
}
|
||||
|
||||
int install_local_mp_kill_hooks(const uint8_t *text, size_t text_size, uint8_t *p_ground_dead)
|
||||
{
|
||||
uint8_t *p_add = local_mp_scan_unique(text, text_size, "MPlayer::addScore", LMP_SIG_MPLAYER_ADD_SCORE);
|
||||
uint8_t *p_dirty = local_mp_scan_unique(text, text_size, "net_mark_dirty", LMP_SIG_NET_MARK_DIRTY);
|
||||
uint8_t *p_dead = local_mp_scan_unique(text, text_size, "onUnitDeadOnce", LMP_SIG_ON_UNIT_DEAD_ONCE);
|
||||
|
||||
if (!p_ground_dead || !p_add || !p_dirty || !p_dead)
|
||||
return 0;
|
||||
|
||||
fn_mplayer_add_score = (MPlayerAddScoreFn)p_add;
|
||||
fn_net_mark_dirty = (NetMarkDirtyFn)p_dirty;
|
||||
|
||||
if (MH_CreateHook(p_ground_dead, (void *)&hook_iground_on_became_dead, (void **)&orig_iground_on_dead) != MH_OK ||
|
||||
MH_EnableHook(p_ground_dead) != MH_OK ||
|
||||
MH_CreateHook(p_dead, (void *)&hook_on_unit_dead_once, (void **)&orig_on_unit_dead_once) != MH_OK ||
|
||||
MH_EnableHook(p_dead) != MH_OK) {
|
||||
log_line("local_mp: failed to install unit-death scoring hooks");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,295 @@
|
||||
/*
|
||||
* LocalMP SessionStatsNet & UnitSessionStat ledger, per-unit rate table,
|
||||
* and center-screen HUD reward banner.
|
||||
*/
|
||||
#include "hooks.h"
|
||||
#include "hook_config.h"
|
||||
#include "local_mp_internal.h"
|
||||
#include "local_mp_offsets.h"
|
||||
|
||||
#include "MinHook.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
typedef struct DagorSimpleStr {
|
||||
const char *ptr;
|
||||
void *alloc;
|
||||
uint64_t len_cap;
|
||||
} DagorSimpleStr;
|
||||
|
||||
typedef void (__fastcall *SessionStatsResetFn)(void *stats_net);
|
||||
typedef uint8_t *(__fastcall *SessionStatsGetUnitFn)(void *stats_net, const char *unit_name);
|
||||
typedef void (__fastcall *StartActualizeClientFn)(void *econ_state, int32_t p2, uint8_t p3);
|
||||
typedef void (__fastcall *HudAddScoreMessageFn)(
|
||||
void *hud, uint32_t event_id, uint32_t msg_type, int32_t xp, int32_t wp,
|
||||
uint32_t delay, void *target_unit, const DagorSimpleStr *str, int64_t a9, int64_t a10
|
||||
);
|
||||
|
||||
static void **g_hud_ptr;
|
||||
static SessionStatsResetFn fn_stats_reset;
|
||||
static SessionStatsGetUnitFn fn_stats_get_unit;
|
||||
static HudAddScoreMessageFn fn_hud_add_score_msg;
|
||||
static StartActualizeClientFn orig_start_actualize;
|
||||
|
||||
static LocalMpUnitRateEntry g_unit_rates[LMP_MAX_UNIT_RATES];
|
||||
static size_t g_unit_rate_count = 0;
|
||||
static char g_last_spawned_unit[64];
|
||||
static int g_finalized_this_match = 0;
|
||||
static const LocalMpUnitRates k_empty_rates = { "", 0.0f, 0.0f, 0.0f, 0.0f, 0.0f };
|
||||
|
||||
static void sat_add_i32(int32_t *dst, int32_t delta)
|
||||
{
|
||||
int64_t sum = (int64_t)(*dst) + (int64_t)delta;
|
||||
if (sum > 0x7fffffffLL) sum = 0x7fffffffLL;
|
||||
if (sum < 0) sum = 0;
|
||||
*dst = (int32_t)sum;
|
||||
}
|
||||
|
||||
static void add_bucket_values(uint8_t *base, size_t bkt_off, int32_t count_inc, int32_t wp, int32_t exp)
|
||||
{
|
||||
uint8_t *b = base + bkt_off;
|
||||
sat_add_i32((int32_t *)(b + LMP_BKT_OFF_COUNT), count_inc);
|
||||
sat_add_i32((int32_t *)(b + LMP_BKT_OFF_EXP), exp);
|
||||
sat_add_i32((int32_t *)(b + LMP_BKT_OFF_WP), wp);
|
||||
sat_add_i32((int32_t *)(b + LMP_BKT_OFF_RAW_EXP), exp);
|
||||
sat_add_i32((int32_t *)(b + LMP_BKT_OFF_RAW_WP), wp);
|
||||
sat_add_i32((int32_t *)(b + LMP_BKT_OFF_NO_BONUS_EXP), exp);
|
||||
sat_add_i32((int32_t *)(b + LMP_BKT_OFF_NO_BONUS_WP), wp);
|
||||
}
|
||||
|
||||
static void record_on_unit(
|
||||
uint8_t *sstat, const char *unit_name, size_t bkt_off,
|
||||
int32_t count_inc, int32_t wp, int32_t exp, float score_delta
|
||||
)
|
||||
{
|
||||
int32_t total_inc = count_inc > 0 ? 1 : 0;
|
||||
uint8_t *ustat;
|
||||
|
||||
add_bucket_values(sstat, bkt_off, count_inc, wp, exp);
|
||||
if (bkt_off != LMP_STAT_BKT_TOTAL)
|
||||
add_bucket_values(sstat, LMP_STAT_BKT_TOTAL, total_inc, wp, exp);
|
||||
sat_add_i32((int32_t *)(sstat + LMP_SSTAT_OFF_EXP_FREE), exp);
|
||||
if (unit_name == NULL || unit_name[0] == '\0' || fn_stats_get_unit == NULL)
|
||||
return;
|
||||
ustat = fn_stats_get_unit(sstat, unit_name);
|
||||
if (ustat == NULL)
|
||||
return;
|
||||
add_bucket_values(ustat, bkt_off, count_inc, wp, exp);
|
||||
if (bkt_off != LMP_STAT_BKT_TOTAL)
|
||||
add_bucket_values(ustat, LMP_STAT_BKT_TOTAL, total_inc, wp, exp);
|
||||
*(float *)(ustat + LMP_USTAT_OFF_SCORE) += score_delta;
|
||||
sat_add_i32((int32_t *)(ustat + LMP_USTAT_OFF_EXP_MOD), exp);
|
||||
sat_add_i32((int32_t *)(ustat + LMP_USTAT_OFF_EXP_MOD_TOTAL), exp);
|
||||
sat_add_i32((int32_t *)(ustat + LMP_USTAT_OFF_EXP_UNIT), exp);
|
||||
sat_add_i32((int32_t *)(ustat + LMP_USTAT_OFF_EXP_UNIT_TOTAL), exp);
|
||||
}
|
||||
|
||||
void local_mp_ledger_reset(void)
|
||||
{
|
||||
uint8_t *econ = local_mp_econ_state();
|
||||
g_unit_rate_count = 0;
|
||||
g_finalized_this_match = 0;
|
||||
memset(g_unit_rates, 0, sizeof(g_unit_rates));
|
||||
memset(g_last_spawned_unit, 0, sizeof(g_last_spawned_unit));
|
||||
local_mp_events_reset();
|
||||
if (econ != NULL && fn_stats_reset != NULL)
|
||||
fn_stats_reset(econ + LMP_ECON_OFF_SESSION_STATS);
|
||||
}
|
||||
|
||||
void local_mp_ledger_store_rates(const LocalMpUnitRates *rates)
|
||||
{
|
||||
size_t i;
|
||||
if (rates == NULL || rates->unit_name[0] == '\0')
|
||||
return;
|
||||
for (i = 0; i < g_unit_rate_count; i++) {
|
||||
if (strcmp(g_unit_rates[i].rates.unit_name, rates->unit_name) == 0) {
|
||||
g_unit_rates[i].rates = *rates;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (g_unit_rate_count < LMP_MAX_UNIT_RATES) {
|
||||
g_unit_rates[g_unit_rate_count].rates = *rates;
|
||||
g_unit_rates[g_unit_rate_count].spawned = 0;
|
||||
g_unit_rate_count++;
|
||||
}
|
||||
}
|
||||
|
||||
void local_mp_ledger_activate_unit(const char *unit_name)
|
||||
{
|
||||
uint8_t *econ = local_mp_econ_state();
|
||||
size_t i;
|
||||
|
||||
if (unit_name == NULL || unit_name[0] == '\0')
|
||||
return;
|
||||
g_finalized_this_match = 0;
|
||||
memset(g_last_spawned_unit, 0, sizeof(g_last_spawned_unit));
|
||||
strncpy(g_last_spawned_unit, unit_name, sizeof(g_last_spawned_unit) - 1);
|
||||
if (econ != NULL && fn_stats_get_unit != NULL)
|
||||
fn_stats_get_unit(econ + LMP_ECON_OFF_SESSION_STATS, unit_name);
|
||||
|
||||
for (i = 0; i < g_unit_rate_count; i++) {
|
||||
if (strcmp(g_unit_rates[i].rates.unit_name, unit_name) == 0) {
|
||||
g_unit_rates[i].spawned = 1;
|
||||
return;
|
||||
}
|
||||
}
|
||||
if (g_unit_rate_count < LMP_MAX_UNIT_RATES) {
|
||||
memset(&g_unit_rates[g_unit_rate_count], 0, sizeof(g_unit_rates[0]));
|
||||
strncpy(g_unit_rates[g_unit_rate_count].rates.unit_name, unit_name,
|
||||
sizeof(g_unit_rates[0].rates.unit_name) - 1);
|
||||
g_unit_rates[g_unit_rate_count].spawned = 1;
|
||||
g_unit_rate_count++;
|
||||
}
|
||||
}
|
||||
|
||||
const char *local_mp_active_player_unit_name(void)
|
||||
{
|
||||
uint8_t *mplayer = g_local_mp_mplayer ? *g_local_mp_mplayer : NULL;
|
||||
const char *hero_name = (g_local_mp_hero && *g_local_mp_hero) ? local_mp_unit_name(*g_local_mp_hero) : NULL;
|
||||
|
||||
if (hero_name != NULL && mplayer != NULL && mplayer[LMP_MP_OFF_GUI_STATE] == LMP_GUI_STATE_PILOT_CONTROL) {
|
||||
local_mp_ledger_activate_unit(hero_name);
|
||||
return hero_name;
|
||||
}
|
||||
return g_last_spawned_unit[0] != '\0' ? g_last_spawned_unit : hero_name;
|
||||
}
|
||||
|
||||
const LocalMpUnitRates *local_mp_ledger_rates_for_unit(const char *unit_name)
|
||||
{
|
||||
const char *target = (unit_name && unit_name[0] != '\0') ? unit_name : local_mp_active_player_unit_name();
|
||||
size_t i;
|
||||
|
||||
if (target != NULL && target[0] != '\0') {
|
||||
for (i = 0; i < g_unit_rate_count; i++) {
|
||||
if (strcmp(g_unit_rates[i].rates.unit_name, target) == 0)
|
||||
return &g_unit_rates[i].rates;
|
||||
}
|
||||
}
|
||||
return &k_empty_rates;
|
||||
}
|
||||
|
||||
void local_mp_ledger_record_event(
|
||||
const char *unit_name, size_t bucket_off, int32_t count_inc, int32_t wp, int32_t exp, float score_delta
|
||||
)
|
||||
{
|
||||
uint8_t *econ = local_mp_econ_state();
|
||||
const char *active_name = (unit_name && unit_name[0] != '\0') ? unit_name : local_mp_active_player_unit_name();
|
||||
|
||||
if (econ == NULL)
|
||||
return;
|
||||
if (active_name != NULL && active_name[0] != '\0')
|
||||
local_mp_ledger_activate_unit(active_name);
|
||||
record_on_unit(econ + LMP_ECON_OFF_SESSION_STATS, active_name,
|
||||
bucket_off, count_inc, wp > 0 ? wp : 0, exp > 0 ? exp : 0, score_delta);
|
||||
}
|
||||
|
||||
void local_mp_ledger_banner(uint32_t event_id, uint32_t msg_type, int32_t xp, int32_t wp, void *target_unit)
|
||||
{
|
||||
void *hud = g_hud_ptr ? *g_hud_ptr : NULL;
|
||||
DagorSimpleStr empty_str = { NULL, g_local_mp_stdmem ? *g_local_mp_stdmem : NULL, 0 };
|
||||
|
||||
if (hud != NULL && fn_hud_add_score_msg != NULL)
|
||||
fn_hud_add_score_msg(hud, event_id, msg_type, xp, wp, 0, target_unit, &empty_str, 0, 0);
|
||||
}
|
||||
|
||||
static size_t count_spawned_units(void)
|
||||
{
|
||||
size_t i, spawned = 0;
|
||||
for (i = 0; i < g_unit_rate_count; i++) {
|
||||
if (g_unit_rates[i].spawned && g_unit_rates[i].rates.wp_per_kill > 0.0f)
|
||||
spawned++;
|
||||
}
|
||||
return spawned;
|
||||
}
|
||||
|
||||
static void finalize_session_stats_before_exit(uint8_t *econ)
|
||||
{
|
||||
uint8_t *sstat = econ + LMP_ECON_OFF_SESSION_STATS;
|
||||
uint8_t *app = g_local_mp_app ? *g_local_mp_app : NULL;
|
||||
uint8_t *rules = app ? *(uint8_t **)(app + LMP_APP_OFF_SCORE_RULES) : NULL;
|
||||
int32_t mstat = rules ? *(int32_t *)(rules + LMP_SCORE_RULES_OFF_MSTATUS) : 0;
|
||||
uint8_t *local_mp = g_local_mp_mplayer ? *g_local_mp_mplayer : NULL;
|
||||
float score = local_mp ? (float)(*(int32_t *)(local_mp + LMP_MP_OFF_SCORE)) : 0.0f;
|
||||
float total_bt = *(float *)(sstat + LMP_STAT_OFF_BATTLE_TIME);
|
||||
float total_st = *(float *)(sstat + LMP_STAT_OFF_SESSION_TIME);
|
||||
float active_sec = total_bt > 1.0f ? total_bt : (total_st * 0.65f);
|
||||
float activity = 0.0f;
|
||||
size_t spawned_count, i;
|
||||
|
||||
if (g_finalized_this_match)
|
||||
return;
|
||||
g_finalized_this_match = 1;
|
||||
*(int32_t *)(sstat + LMP_SSTAT_OFF_RESULT) = (mstat == LMP_MISSION_STATUS_SUCCESS) ? LMP_STATS_RESULT_SUCCESS :
|
||||
((mstat == LMP_MISSION_STATUS_FAIL) ? LMP_STATS_RESULT_FAIL : LMP_STATS_RESULT_IN_PROGRESS);
|
||||
|
||||
if (score > 0.0f || active_sec > 3.0f) {
|
||||
activity = (score / 1200.0f) * 0.65f + (active_sec / 480.0f) * 0.35f;
|
||||
if (activity < 0.15f) activity = 0.15f;
|
||||
if (activity > 1.0f) activity = 1.0f;
|
||||
}
|
||||
*(float *)(sstat + LMP_SSTAT_OFF_ACTIVITY) = activity;
|
||||
if (total_bt < 1.0f && active_sec > 0.0f)
|
||||
*(float *)(sstat + LMP_STAT_OFF_BATTLE_TIME) = active_sec;
|
||||
|
||||
spawned_count = count_spawned_units();
|
||||
if (spawned_count == 0)
|
||||
return;
|
||||
|
||||
for (i = 0; i < g_unit_rate_count; i++) {
|
||||
const LocalMpUnitRates *r = &g_unit_rates[i].rates;
|
||||
uint8_t *ustat;
|
||||
float u_bt, u_st, share_st, eff_sec;
|
||||
if (!g_unit_rates[i].spawned || r->wp_per_kill <= 0.0f)
|
||||
continue;
|
||||
ustat = fn_stats_get_unit ? fn_stats_get_unit(sstat, r->unit_name) : NULL;
|
||||
u_bt = ustat ? *(float *)(ustat + LMP_STAT_OFF_BATTLE_TIME) : 0.0f;
|
||||
u_st = ustat ? *(float *)(ustat + LMP_STAT_OFF_SESSION_TIME) : 0.0f;
|
||||
share_st = total_st > 1.0f ? (total_st / (float)spawned_count) : active_sec;
|
||||
eff_sec = u_bt > 1.0f ? u_bt : (u_st > 1.0f ? u_st * 0.65f : (active_sec / (float)spawned_count));
|
||||
if (ustat != NULL && u_st < 1.0f && share_st > 0.5f)
|
||||
*(float *)(ustat + LMP_STAT_OFF_SESSION_TIME) = share_st;
|
||||
if (eff_sec > 2.0f && activity > 0.0f) {
|
||||
int32_t bt_wp = (int32_t)((eff_sec / 60.0f) * r->battle_time_award * activity + 0.5f);
|
||||
int32_t bt_rp = (int32_t)((eff_sec * 1.4f) * r->exp_mul * activity + 0.5f);
|
||||
if (ustat != NULL && u_bt < 1.0f)
|
||||
*(float *)(ustat + LMP_STAT_OFF_BATTLE_TIME) = eff_sec;
|
||||
record_on_unit(sstat, r->unit_name, LMP_STAT_BKT_BATTLE_TIME, 1, bt_wp, bt_rp, 0.0f);
|
||||
if (*(int32_t *)(sstat + LMP_SSTAT_OFF_RESULT) == LMP_STATS_RESULT_SUCCESS) {
|
||||
record_on_unit(sstat, r->unit_name, LMP_STAT_BKT_MISSION, 1,
|
||||
(int32_t)((float)bt_wp * r->win_k + 0.5f), (int32_t)((float)bt_rp * r->win_k + 0.5f), 0.0f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static void __fastcall hook_start_actualize_client(void *econ_state, int32_t p2, uint8_t p3)
|
||||
{
|
||||
if (local_mp_is_host() && econ_state != NULL)
|
||||
finalize_session_stats_before_exit((uint8_t *)econ_state);
|
||||
orig_start_actualize(econ_state, p2, p3);
|
||||
}
|
||||
|
||||
int install_local_mp_ledger_hooks(const uint8_t *text, size_t text_size, uint8_t *p_ground_dead)
|
||||
{
|
||||
uint8_t *p_hud_msg = local_mp_scan_unique(text, text_size, "Hud::addScoreMessage", LMP_SIG_HUD_ADD_SCORE_MSG);
|
||||
uint8_t *p_reset = local_mp_scan_unique(text, text_size, "SessionStatsNet::reset", LMP_SIG_SESSION_STATS_RESET);
|
||||
uint8_t *p_get_u = local_mp_scan_unique(text, text_size, "SessionStatsNet::getOrCreateUnitStat", LMP_SIG_SESSION_STATS_GET_UNIT);
|
||||
uint8_t *p_actualize = local_mp_scan_unique(text, text_size, "GameSaveData::startActualizeClient", LMP_SIG_START_ACTUALIZE_CLIENT);
|
||||
|
||||
if (!p_ground_dead || !p_hud_msg || !p_reset || !p_get_u || !p_actualize)
|
||||
return 0;
|
||||
if (p_ground_dead[0xa19] != 0x48 || p_ground_dead[0xa1a] != 0x8b || p_ground_dead[0xa1b] != 0x0d)
|
||||
return 0;
|
||||
|
||||
g_hud_ptr = (void **)local_mp_resolve_rip(p_ground_dead + 0xa19, 3, 7);
|
||||
fn_hud_add_score_msg = (HudAddScoreMessageFn)p_hud_msg;
|
||||
fn_stats_reset = (SessionStatsResetFn)p_reset;
|
||||
fn_stats_get_unit = (SessionStatsGetUnitFn)p_get_u;
|
||||
|
||||
if (MH_CreateHook(p_actualize, (void *)&hook_start_actualize_client, (void **)&orig_start_actualize) != MH_OK ||
|
||||
MH_EnableHook(p_actualize) != MH_OK) {
|
||||
log_line("local_mp: failed to install startActualizeClient hook");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,254 @@
|
||||
/*
|
||||
* LocalMP vehicle loadout, modification map, decals, 3D attachables, and crew-skill bridge.
|
||||
*
|
||||
* Stores per-unit economic multipliers in `LocalMpUnitRateEntry[32]` without touching
|
||||
* `SessionStatsNet` during respawn-screen previews (`requestChangeUnitSilent`).
|
||||
*/
|
||||
#include "hooks.h"
|
||||
#include "hook_config.h"
|
||||
#include "local_mp_internal.h"
|
||||
#include "local_mp_offsets.h"
|
||||
|
||||
#include "MinHook.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
typedef void (__fastcall *SemChangeAircraftSendFn)(
|
||||
void *self, const char *unit_name, const char *weapon_name, const void *modifications_blk,
|
||||
const char *skin_name, const void *custom_preset_blk, uint8_t flags_byte,
|
||||
const void *serialized_bullets, int32_t crew_id, int32_t resp_base_id, float fuel,
|
||||
float gun_targeting_dist, uint8_t vertical_targeting, float bomb_activation_time,
|
||||
uint16_t extra_u16, uint8_t extra_b1, uint8_t extra_b2, const char *extra_str,
|
||||
const char *custom_skin, int32_t slot_id, const void *spare_data, int32_t spare_type
|
||||
);
|
||||
typedef void *(__fastcall *ReflCtorFn)(void *refl);
|
||||
typedef void (__fastcall *ReflDtorFn)(void *refl);
|
||||
typedef uint8_t (__fastcall *UnitChangeAircraftFn)(void *unit, void *refl, uint8_t async);
|
||||
typedef void *(__fastcall *DataBlockSetFromFn)(void *dst_blk, const void *src_blk, const char *src_fname);
|
||||
typedef void (__fastcall *DataBlockDtorFn)(void *blk);
|
||||
typedef float (__fastcall *DataBlockGetRealFn)(const void *blk, const char *name, float def);
|
||||
typedef void (__fastcall *BulletSetVecAssignFn)(void *dst_vec, const void *first, const void *last);
|
||||
typedef void *(__fastcall *GetDecalsBlkFn)(
|
||||
void *econ, void *out_blk, const char *unit, const char *skin, const char *def_key, const char *cskin
|
||||
);
|
||||
typedef const void *(__fastcall *GetAttachablesBlkFn)(
|
||||
void *econ, const char *unit, const char *skin, const char *cskin
|
||||
);
|
||||
typedef uint64_t (__fastcall *StrHashFnv1Fn)(const char *str, size_t len);
|
||||
typedef int32_t (__fastcall *NameMapAddNameIdFn)(void *map, const char *str, size_t len, uint64_t hash);
|
||||
typedef void (__fastcall *CrewSkillsInitFn)(void *crew_skills, void *econ_state, const char *unit_name, float mult);
|
||||
|
||||
static SemChangeAircraftSendFn orig_sem_send;
|
||||
static ReflCtorFn fn_refl_ctor;
|
||||
static ReflDtorFn fn_refl_dtor;
|
||||
static UnitChangeAircraftFn fn_unit_change_aircraft;
|
||||
static DataBlockSetFromFn fn_datablock_set_from;
|
||||
static DataBlockDtorFn fn_datablock_dtor;
|
||||
static DataBlockGetRealFn fn_datablock_get_real;
|
||||
static BulletSetVecAssignFn fn_bullet_vec_assign;
|
||||
static GetDecalsBlkFn fn_get_decals_blk;
|
||||
static GetAttachablesBlkFn fn_get_attachables_blk;
|
||||
static StrHashFnv1Fn fn_str_hash;
|
||||
static NameMapAddNameIdFn fn_namemap_add;
|
||||
static CrewSkillsInitFn fn_crew_skills_init;
|
||||
|
||||
static void populate_namemap_csv(void *map, const char *csv)
|
||||
{
|
||||
const char *p = csv;
|
||||
char tok[96];
|
||||
|
||||
if (map == NULL || p == NULL || *p == '\0')
|
||||
return;
|
||||
while (*p != '\0') {
|
||||
const char *sep = strchr(p, ';');
|
||||
size_t len = sep ? (size_t)(sep - p) : strlen(p);
|
||||
if (len > 0 && len < sizeof(tok)) {
|
||||
memcpy(tok, p, len);
|
||||
tok[len] = '\0';
|
||||
fn_namemap_add(map, tok, len, fn_str_hash(tok, len));
|
||||
}
|
||||
if (sep == NULL)
|
||||
break;
|
||||
p = sep + 1;
|
||||
}
|
||||
}
|
||||
|
||||
static int parse_spawn_metadata_blk(const char *unit_name, const void *mods_blk, uint8_t *refl)
|
||||
{
|
||||
LocalMpUnitRates rates;
|
||||
const char *enabled_csv = "";
|
||||
const char *disabled_csv = "";
|
||||
const char *silent_str = "0";
|
||||
|
||||
memset(&rates, 0, sizeof(rates));
|
||||
if (unit_name != NULL)
|
||||
strncpy(rates.unit_name, unit_name, sizeof(rates.unit_name) - 1);
|
||||
|
||||
if (mods_blk != NULL && g_lmp_datablock_get_str != NULL) {
|
||||
enabled_csv = g_lmp_datablock_get_str(mods_blk, "enabledMods", "");
|
||||
disabled_csv = g_lmp_datablock_get_str(mods_blk, "disabledMods", "");
|
||||
silent_str = g_lmp_datablock_get_str(mods_blk, "isSilentPreview", "0");
|
||||
rates.wp_per_kill = fn_datablock_get_real(mods_blk, "wpPerKill", 0.0f);
|
||||
rates.exp_mul = fn_datablock_get_real(mods_blk, "expMul", 0.0f);
|
||||
rates.battle_time_award = fn_datablock_get_real(mods_blk, "battleTimeAward", 0.0f);
|
||||
rates.ai_kill_k = fn_datablock_get_real(mods_blk, "aiKillK", 0.0f);
|
||||
rates.win_k = fn_datablock_get_real(mods_blk, "winK", 0.0f);
|
||||
}
|
||||
|
||||
if (refl != NULL) {
|
||||
populate_namemap_csv(refl + LMP_REFL_OFF_ENABLED_MODS, enabled_csv);
|
||||
populate_namemap_csv(refl + LMP_REFL_OFF_DISABLED_MODS, disabled_csv);
|
||||
}
|
||||
if (rates.unit_name[0] != '\0' && rates.wp_per_kill > 0.0f)
|
||||
local_mp_ledger_store_rates(&rates);
|
||||
return silent_str != NULL && strcmp(silent_str, "1") == 0;
|
||||
}
|
||||
|
||||
static void populate_cosmetics(
|
||||
uint8_t *refl, uint8_t *econ_state, const char *unit_name, const char *skin_name, const char *custom_skin
|
||||
)
|
||||
{
|
||||
__declspec(align(16)) uint8_t decals_tmp[64];
|
||||
const char *u = unit_name ? unit_name : "";
|
||||
const char *s = skin_name ? skin_name : "";
|
||||
const char *c = custom_skin ? custom_skin : "";
|
||||
const void *att_blk;
|
||||
|
||||
memset(decals_tmp, 0, sizeof(decals_tmp));
|
||||
if (fn_get_decals_blk(econ_state, decals_tmp, u, s, "defaultDecals", c) != NULL) {
|
||||
fn_datablock_set_from(refl + LMP_REFL_OFF_DECALS_BLK, decals_tmp, NULL);
|
||||
fn_datablock_dtor(decals_tmp);
|
||||
}
|
||||
att_blk = fn_get_attachables_blk(econ_state, u, s, c);
|
||||
if (att_blk != NULL)
|
||||
fn_datablock_set_from(refl + LMP_REFL_OFF_ATTACHABLES_BLK, att_blk, NULL);
|
||||
}
|
||||
|
||||
static void apply_mplayer_spawn_base(uint8_t *mplayer, int32_t req_base_id)
|
||||
{
|
||||
*(int32_t *)(mplayer + LMP_MP_OFF_RESP_BASE_ID) = req_base_id;
|
||||
*(int32_t *)(mplayer + LMP_MP_OFF_SPAWN_DELAY_A) = -1;
|
||||
*(int32_t *)(mplayer + LMP_MP_OFF_SPAWN_DELAY_B) = -1;
|
||||
*(float *)(mplayer + LMP_MP_OFF_SPAWN_POS_X) = 0.0f;
|
||||
*(float *)(mplayer + LMP_MP_OFF_SPAWN_POS_Y) = 0.0f;
|
||||
*(float *)(mplayer + LMP_MP_OFF_SPAWN_POS_Z) = 0.0f;
|
||||
}
|
||||
|
||||
static void __fastcall hook_sem_change_aircraft_send(
|
||||
void *self, const char *unit_name, const char *weapon_name, const void *modifications_blk,
|
||||
const char *skin_name, const void *custom_preset_blk, uint8_t flags_byte,
|
||||
const void *serialized_bullets, int32_t crew_id, int32_t resp_base_id, float fuel,
|
||||
float gun_targeting_dist, uint8_t vertical_targeting, float bomb_activation_time,
|
||||
uint16_t extra_u16, uint8_t extra_b1, uint8_t extra_b2, const char *extra_str,
|
||||
const char *custom_skin, int32_t slot_id, const void *spare_data, int32_t spare_type
|
||||
)
|
||||
{
|
||||
uint8_t *hero, *mplayer, *econ_state, *req;
|
||||
const void *bullets_begin, *bullets_end;
|
||||
void *crew_skills;
|
||||
int32_t req_slot_id, req_base_id, req_spare_type;
|
||||
int is_silent;
|
||||
__declspec(align(16)) uint8_t refl[LMP_REFL_SIZE];
|
||||
|
||||
if (!local_mp_is_host()) {
|
||||
orig_sem_send(self, unit_name, weapon_name, modifications_blk, skin_name, custom_preset_blk,
|
||||
flags_byte, serialized_bullets, crew_id, resp_base_id, fuel, gun_targeting_dist,
|
||||
vertical_targeting, bomb_activation_time, extra_u16, extra_b1, extra_b2,
|
||||
extra_str, custom_skin, slot_id, spare_data, spare_type);
|
||||
return;
|
||||
}
|
||||
|
||||
hero = g_local_mp_hero ? *g_local_mp_hero : NULL;
|
||||
mplayer = g_local_mp_mplayer ? *g_local_mp_mplayer : (hero ? *(uint8_t **)(hero + LMP_UNIT_OFF_MPLAYER) : NULL);
|
||||
econ_state = local_mp_econ_state();
|
||||
if (hero == NULL || mplayer == NULL || econ_state == NULL)
|
||||
return;
|
||||
|
||||
if (mplayer[LMP_MP_OFF_GUI_STATE] == LMP_GUI_STATE_PILOT_CONTROL &&
|
||||
parse_spawn_metadata_blk(unit_name, modifications_blk, NULL)) {
|
||||
g_lmp_aircraft_change_result(econ_state, 0);
|
||||
return;
|
||||
}
|
||||
|
||||
req = econ_state + LMP_ECON_OFF_CHANGE_REQ;
|
||||
bullets_begin = *(const void **)(req + LMP_REQ_OFF_BULLETS_BEGIN);
|
||||
bullets_end = *(const void **)(req + LMP_REQ_OFF_BULLETS_END);
|
||||
req_slot_id = *(int32_t *)(req + LMP_REQ_OFF_SLOT_ID);
|
||||
req_base_id = *(int32_t *)(req + LMP_REQ_OFF_RESP_BASE_ID);
|
||||
req_spare_type = *(int32_t *)(req + LMP_REQ_OFF_SPARE_TYPE);
|
||||
apply_mplayer_spawn_base(mplayer, req_base_id);
|
||||
|
||||
memset(refl, 0, sizeof(refl));
|
||||
fn_refl_ctor(refl);
|
||||
*(char **)(refl + LMP_REFL_OFF_UNIT_NAME) = local_mp_strdup(unit_name);
|
||||
*(char **)(refl + LMP_REFL_OFF_WEAPON_NAME) = local_mp_strdup(weapon_name);
|
||||
*(char **)(refl + LMP_REFL_OFF_SKIN_NAME) = local_mp_strdup(skin_name);
|
||||
*(char **)(refl + LMP_REFL_OFF_CUSTOM_SKIN) = local_mp_strdup(custom_skin);
|
||||
populate_cosmetics(refl, econ_state, unit_name, skin_name, custom_skin);
|
||||
is_silent = parse_spawn_metadata_blk(unit_name, modifications_blk, refl);
|
||||
if (custom_preset_blk != NULL)
|
||||
fn_datablock_set_from(refl + LMP_REFL_OFF_CUSTOM_PRESET_BLK, custom_preset_blk, NULL);
|
||||
if (bullets_begin != NULL && bullets_end != NULL && bullets_end > bullets_begin)
|
||||
fn_bullet_vec_assign(refl + LMP_REFL_OFF_BULLETS_VEC, bullets_begin, bullets_end);
|
||||
|
||||
*(uint32_t *)(refl + LMP_REFL_OFF_FLAGS) |= 0x50u;
|
||||
*(float *)(refl + LMP_REFL_OFF_FUEL) = fuel;
|
||||
*(float *)(refl + LMP_REFL_OFF_GUN_CONVERGENCE) = gun_targeting_dist;
|
||||
refl[LMP_REFL_OFF_VERT_TARGETING] = vertical_targeting ? 1u : 0u;
|
||||
*(float *)(refl + LMP_REFL_OFF_BOMB_FUSE) = bomb_activation_time;
|
||||
|
||||
fn_unit_change_aircraft(hero, refl, 1);
|
||||
fn_refl_dtor(refl);
|
||||
|
||||
crew_skills = *(void **)(hero + LMP_UNIT_OFF_CREW_SKILLS);
|
||||
if (crew_skills != NULL && unit_name != NULL && unit_name[0] != '\0')
|
||||
fn_crew_skills_init(crew_skills, econ_state, unit_name, 1.0f);
|
||||
if (mplayer[LMP_MP_OFF_GUI_STATE] != LMP_GUI_STATE_PILOT_CONTROL &&
|
||||
mplayer[LMP_MP_OFF_GUI_STATE] != LMP_GUI_STATE_CA_READY)
|
||||
g_lmp_set_player_gui_state((int32_t)mplayer[LMP_MP_OFF_PID], LMP_GUI_STATE_CA_READY);
|
||||
|
||||
local_mp_players_queue_spawn(req_slot_id, req_spare_type, is_silent);
|
||||
log_line("local_mp: configured unit='%s' weapon='%s' slot=%d silent=%d",
|
||||
unit_name ? unit_name : "", weapon_name ? weapon_name : "", (int)req_slot_id, is_silent);
|
||||
}
|
||||
|
||||
int install_local_mp_loadout_hooks(const uint8_t *text, size_t text_size)
|
||||
{
|
||||
uint8_t *p_sem_send = local_mp_scan_unique(text, text_size, "SemChangeAircraftRequest::send", LMP_SIG_SEM_CHANGE_AIRCRAFT_SEND);
|
||||
uint8_t *p_refl_ctor = local_mp_scan_unique(text, text_size, "ChangeUnitReflection::ctor", LMP_SIG_REFL_CTOR);
|
||||
uint8_t *p_refl_dtor = local_mp_scan_unique(text, text_size, "ChangeUnitReflection::dtor", LMP_SIG_REFL_DTOR);
|
||||
uint8_t *p_change_air = local_mp_scan_unique(text, text_size, "Unit::changeAircraft", LMP_SIG_UNIT_CHANGE_AIRCRAFT);
|
||||
uint8_t *p_blk_set = local_mp_scan_unique(text, text_size, "DataBlock::setFrom", LMP_SIG_DATABLOCK_SET_FROM);
|
||||
uint8_t *p_blk_dtor = local_mp_scan_unique(text, text_size, "DataBlock::~DataBlock", LMP_SIG_DATABLOCK_DTOR);
|
||||
uint8_t *p_blk_real = local_mp_scan_unique(text, text_size, "DataBlock::getReal", LMP_SIG_DATABLOCK_GET_REAL);
|
||||
uint8_t *p_bullets = local_mp_scan_unique(text, text_size, "BulletSetVec::assign", LMP_SIG_BULLET_VEC_ASSIGN);
|
||||
uint8_t *p_decals = local_mp_scan_unique(text, text_size, "GameSaveData::getDecalsBlk", LMP_SIG_GET_DECALS_BLK);
|
||||
uint8_t *p_attach = local_mp_scan_unique(text, text_size, "GameSaveData::getAttachablesBlk", LMP_SIG_GET_ATTACHABLES_BLK);
|
||||
uint8_t *p_hash = local_mp_scan_unique(text, text_size, "str_hash_fnv1", LMP_SIG_STR_HASH_FNV1);
|
||||
uint8_t *p_nm_add = local_mp_scan_unique(text, text_size, "OAHashNameMap::addNameId", LMP_SIG_NAMEMAP_ADD_NAME_ID);
|
||||
uint8_t *p_crew = local_mp_scan_unique(text, text_size, "UnitCrewSkills::initFromSave", LMP_SIG_CREW_SKILLS_INIT);
|
||||
|
||||
if (!p_sem_send || !p_refl_ctor || !p_refl_dtor || !p_change_air || !p_blk_set || !p_blk_dtor ||
|
||||
!p_blk_real || !p_bullets || !p_decals || !p_attach || !p_hash || !p_nm_add || !p_crew)
|
||||
return 0;
|
||||
|
||||
fn_refl_ctor = (ReflCtorFn)p_refl_ctor;
|
||||
fn_refl_dtor = (ReflDtorFn)p_refl_dtor;
|
||||
fn_unit_change_aircraft = (UnitChangeAircraftFn)p_change_air;
|
||||
fn_datablock_set_from = (DataBlockSetFromFn)p_blk_set;
|
||||
fn_datablock_dtor = (DataBlockDtorFn)p_blk_dtor;
|
||||
fn_datablock_get_real = (DataBlockGetRealFn)p_blk_real;
|
||||
fn_bullet_vec_assign = (BulletSetVecAssignFn)p_bullets;
|
||||
fn_get_decals_blk = (GetDecalsBlkFn)p_decals;
|
||||
fn_get_attachables_blk = (GetAttachablesBlkFn)p_attach;
|
||||
fn_str_hash = (StrHashFnv1Fn)p_hash;
|
||||
fn_namemap_add = (NameMapAddNameIdFn)p_nm_add;
|
||||
fn_crew_skills_init = (CrewSkillsInitFn)p_crew;
|
||||
|
||||
if (MH_CreateHook(p_sem_send, (void *)&hook_sem_change_aircraft_send, (void **)&orig_sem_send) != MH_OK ||
|
||||
MH_EnableHook(p_sem_send) != MH_OK) {
|
||||
log_line("local_mp: failed to install SemChangeAircraftRequest::send hook");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
@@ -0,0 +1,297 @@
|
||||
/*
|
||||
* Centralized struct offsets, RIP-relative displacements, and .text signatures
|
||||
* for the War Thunder 2.61.0.37 LocalMP in-process host bridge.
|
||||
*/
|
||||
#pragma once
|
||||
|
||||
#define LMP_GUI_STATE_PILOT_CONTROL 2
|
||||
#define LMP_GUI_STATE_CA_SELECT 6
|
||||
#define LMP_GUI_STATE_CA_READY 8
|
||||
|
||||
#define LMP_MISSION_STATUS_RUNNING 1
|
||||
#define LMP_MISSION_STATUS_SUCCESS 2
|
||||
#define LMP_MISSION_STATUS_FAIL 3
|
||||
#define LMP_STATS_RESULT_IN_PROGRESS 0
|
||||
#define LMP_STATS_RESULT_SUCCESS 1
|
||||
#define LMP_STATS_RESULT_FAIL 2
|
||||
|
||||
#define LMP_EXP_EVENT_CAPTURE_ZONE 2u
|
||||
#define LMP_EXP_EVENT_KILL 5u
|
||||
#define LMP_EXP_EVENT_KILL_GROUND 6u
|
||||
#define LMP_EXP_EVENT_ASSIST 9u
|
||||
#define LMP_EXP_EVENT_CRITICAL_HIT 10u
|
||||
#define LMP_EXP_EVENT_HIT 13u
|
||||
#define LMP_EXP_EVENT_UNIT_DAMAGE 24u
|
||||
#define LMP_EXP_EVENT_DEATH 30u
|
||||
#define LMP_EXP_EVENT_SEVERE_DAMAGE 35u
|
||||
#define LMP_EXP_EVENT_KILL_HUMAN 39u
|
||||
#define LMP_EXP_EVENT_COUNT 45u
|
||||
|
||||
/*
|
||||
* @anchor "localMP"
|
||||
* @anchor "get_local_player_country"
|
||||
* @anchor "mpDom1"
|
||||
* @anchor "mpHadAlivePlayers"
|
||||
* @anchor "guiscriptutils::is_crew_slot_was_ready_at_host"
|
||||
* @anchor "customBots"
|
||||
* @anchor "botDeviationLimits"
|
||||
* @anchor "Reflection: invalid object 0x%p"
|
||||
*/
|
||||
#define LMP_MP_MGR_OFF_IS_HOST 0x0060u
|
||||
#define LMP_MP_MGR_OFF_IS_LOCAL_MP 0x0061u
|
||||
#define LMP_MP_MGR_OFF_TEAM1_COUNTRIES 0x0150u
|
||||
#define LMP_MP_MGR_OFF_TEAM2_COUNTRIES 0x0170u
|
||||
#define LMP_MP_MGR_OFF_MP_CHAT 0x01f0u
|
||||
#define LMP_MP_MGR_OFF_CHAT_HOST 0x01f8u
|
||||
#define LMP_TAB_OFF_DATA 0x0000u
|
||||
#define LMP_TAB_OFF_ALLOC 0x0008u
|
||||
#define LMP_TAB_OFF_COUNT 0x0010u
|
||||
#define LMP_TAB_OFF_CAPACITY 0x0014u
|
||||
#define LMP_APP_OFF_SCORE_RULES 0x03e0u
|
||||
#define LMP_SCORE_RULES_OFF_MSTATUS 0x00f0u
|
||||
#define LMP_APP_OFF_ECON_HOLDER 0x03f0u
|
||||
#define LMP_ECON_HOLDER_OFF_STATE 0x09a8u
|
||||
#define LMP_MIS_OFF_AXIS_COUNTRY 0x00c8u
|
||||
#define LMP_MIS_OFF_ALLIES_COUNTRY 0x00d0u
|
||||
#define LMP_MIS_OFF_ARCADE_COUNTRY 0x01d0u
|
||||
#define LMP_MIS_OFF_CUSTOM_BOTS 0x0718u
|
||||
#define LMP_MATCH_INFO_OFF_TEAM 0x0004u
|
||||
|
||||
/*
|
||||
* @anchor "set_aircraft_accepted_cb"
|
||||
* @anchor "warpoints::stat_get_exp current exp %d"
|
||||
* @anchor "GameSaveData::startActualizeClient"
|
||||
*/
|
||||
#define LMP_ECON_OFF_CHANGE_REQ 0xf578u
|
||||
#define LMP_ECON_OFF_SESSION_STATS 0xf678u
|
||||
#define LMP_REQ_OFF_BULLETS_BEGIN 0x0090u
|
||||
#define LMP_REQ_OFF_BULLETS_END 0x0098u
|
||||
#define LMP_REQ_OFF_RESP_BASE_ID 0x00b8u
|
||||
#define LMP_REQ_OFF_SPARE_TYPE 0x00c0u
|
||||
#define LMP_REQ_OFF_SLOT_ID 0x00e4u
|
||||
|
||||
/*
|
||||
* @anchor "get_mplayers_list"
|
||||
* @anchor "kills"
|
||||
* @anchor "teamKills"
|
||||
* @anchor "deaths"
|
||||
* @anchor "groundKills"
|
||||
* @anchor "humanKills"
|
||||
* @anchor "navalKills"
|
||||
* @anchor "aiKills"
|
||||
* @anchor "aiGroundKills"
|
||||
* @anchor "aiNavalKills"
|
||||
* @anchor "assists"
|
||||
* @anchor "captureZone"
|
||||
* @anchor "awardDamage"
|
||||
* @anchor "airSevereDamage"
|
||||
* @anchor "shipSevereDamage"
|
||||
*/
|
||||
#define LMP_MP_OFF_PID 0x0008u
|
||||
#define LMP_MP_OFF_USER_ID 0x00b8u
|
||||
#define LMP_MP_OFF_FLAGS 0x01d8u
|
||||
#define LMP_MP_OFF_TEAM 0x0228u
|
||||
#define LMP_MP_OFF_FALLBACK_SCORE 0x02d8u
|
||||
#define LMP_MP_OFF_BROKEN_SLOTS_MASK 0x04d0u
|
||||
#define LMP_MP_OFF_USED_SPARES_MASK 0x0520u
|
||||
#define LMP_MP_OFF_GUI_STATE 0x0640u
|
||||
#define LMP_MP_OFF_UNIT_EID 0x0850u
|
||||
#define LMP_MP_OFF_SUPPORT_UNIT_EID 0x0880u
|
||||
#define LMP_MP_FLAG_SPECTATOR_MASK 0x00020020u
|
||||
#define LMP_MP_OFF_SCORE 0x08f8u
|
||||
#define LMP_MP_OFF_KILLS 0x09d8u
|
||||
#define LMP_MP_OFF_TEAM_KILLS 0x09dau
|
||||
#define LMP_MP_OFF_DEATHS 0x09dcu
|
||||
#define LMP_MP_OFF_GROUND_KILLS 0x09deu
|
||||
#define LMP_MP_OFF_HUMAN_KILLS 0x09e0u
|
||||
#define LMP_MP_OFF_NAVAL_KILLS 0x09e2u
|
||||
#define LMP_MP_OFF_AI_KILLS 0x09e4u
|
||||
#define LMP_MP_OFF_AI_GROUND_KILLS 0x09e6u
|
||||
#define LMP_MP_OFF_AI_NAVAL_KILLS 0x09e8u
|
||||
#define LMP_MP_OFF_ASSISTS 0x09ecu
|
||||
#define LMP_MP_OFF_CAPTURE_ZONE 0x09eeu
|
||||
#define LMP_MP_OFF_AWARD_DAMAGE 0x0a00u
|
||||
#define LMP_MP_OFF_AIR_SEVERE_DMG 0x0a06u
|
||||
#define LMP_MP_OFF_SHIP_SEVERE_DMG 0x0a08u
|
||||
#define LMP_MP_OFF_STAT_DIRTY 0x0a10u
|
||||
#define LMP_MP_OFF_STAT_PAYLOAD 0x0a30u
|
||||
#define LMP_MP_OFF_RESP_BASE_ID 0x0bd8u
|
||||
#define LMP_MP_OFF_SPAWN_DELAY_A 0x0bf4u
|
||||
#define LMP_MP_OFF_SPAWN_DELAY_B 0x0bf8u
|
||||
#define LMP_MP_OFF_SPAWN_POS_X 0x0bfcu
|
||||
#define LMP_MP_OFF_SPAWN_POS_Y 0x0c00u
|
||||
#define LMP_MP_OFF_SPAWN_POS_Z 0x0c04u
|
||||
|
||||
/*
|
||||
* @anchor "unit__playerId"
|
||||
* @anchor "setMyPlayer uid:%i eid:%08x ptr:%p pid:%d (saved pid:%d)"
|
||||
* @anchor "IGroundModel__onBecameDead"
|
||||
*/
|
||||
#define LMP_UNIT_OFF_ALIVE_STATE 0x0088u
|
||||
#define LMP_UNIT_OFF_TYPE 0x008cu
|
||||
#define LMP_UNIT_OFF_DEAD_FLAGS 0x0090u
|
||||
#define LMP_UNIT_OFF_SEVERE_IDX 0x06b0u
|
||||
#define LMP_UNIT_OFF_SEVERE_PID 0x06d0u
|
||||
#define LMP_UNIT_OFF_SEVERE_UID 0x0708u
|
||||
#define LMP_UNIT_OFF_BAIL_STATE 0x0f90u
|
||||
#define LMP_UNIT_OFF_MPLAYER 0x0f98u
|
||||
#define LMP_UNIT_DEAD_FLAGS_MASK 0x01000014u
|
||||
#define LMP_UNIT_TYPE_HELICOPTER 0x000du
|
||||
#define LMP_UNIT_OFF_ARMY 0x1010u
|
||||
#define LMP_UNIT_OFF_PID 0x1018u
|
||||
#define LMP_UNIT_OFF_INFO 0x1020u
|
||||
#define LMP_UNIT_INFO_OFF_NAME 0x0010u
|
||||
#define LMP_UNIT_OFF_CREW_SKILLS 0x10a8u
|
||||
#define LMP_UNIT_VTF_CHOOSE_OFFENDER 0x0498u
|
||||
#define LMP_UNIT_OFF_SKIP_KILL 0x3058u
|
||||
#define LMP_IGM_OFF_OFFENDERS_PTR 0x17c0u
|
||||
#define LMP_IGM_OFF_OFFENDERS_CNT 0x17d0u
|
||||
#define LMP_IGM_OFF_KILLER_PID 0x1a08u
|
||||
#define LMP_IGM_OFF_KILLER_ARMY 0x1a04u
|
||||
#define LMP_IGM_OFF_KILLER_UID 0x1a40u
|
||||
#define LMP_IGM_OFF_DEAD_SILENT 0x1c19u
|
||||
#define LMP_IGM_OFF_ALREADY_DEAD 0x2101u
|
||||
#define LMP_IGM_OFF_BAILOUT_DEAD 0x3888u
|
||||
#define LMP_OFFENDER_STRIDE 0x0160u
|
||||
#define LMP_OFFENDER_OFF_ARMY 0x001cu
|
||||
#define LMP_OFFENDER_OFF_PID 0x0020u
|
||||
#define LMP_OFFENDER_OFF_UID 0x0058u
|
||||
#define LMP_OFFENDER_OFF_ASSIST_SENT 0x0148u
|
||||
|
||||
/*
|
||||
* @anchor "defaultDecals"
|
||||
* @anchor "slaveAttachables"
|
||||
* @anchor "bulletsWeapon%i"
|
||||
*/
|
||||
#define LMP_REFL_SIZE 0x0200u
|
||||
#define LMP_REFL_OFF_UNIT_NAME 0x0050u
|
||||
#define LMP_REFL_OFF_WEAPON_NAME 0x0058u
|
||||
#define LMP_REFL_OFF_SKIN_NAME 0x0060u
|
||||
#define LMP_REFL_OFF_CUSTOM_SKIN 0x0068u
|
||||
#define LMP_REFL_OFF_DECALS_BLK 0x0070u
|
||||
#define LMP_REFL_OFF_ATTACHABLES_BLK 0x0090u
|
||||
#define LMP_REFL_OFF_CUSTOM_PRESET_BLK 0x00b0u
|
||||
#define LMP_REFL_OFF_FLAGS 0x00d0u
|
||||
#define LMP_REFL_OFF_FUEL 0x00d8u
|
||||
#define LMP_REFL_OFF_GUN_CONVERGENCE 0x00dcu
|
||||
#define LMP_REFL_OFF_VERT_TARGETING 0x00e0u
|
||||
#define LMP_REFL_OFF_BOMB_FUSE 0x00e4u
|
||||
#define LMP_REFL_OFF_ENABLED_MODS 0x00f0u
|
||||
#define LMP_REFL_OFF_DISABLED_MODS 0x0140u
|
||||
#define LMP_REFL_OFF_BULLETS_VEC 0x0190u
|
||||
|
||||
/*
|
||||
* @anchor "GameSaveData::addScoreMessage - bad messageType received %d"
|
||||
* @anchor "numAirKills"
|
||||
* @anchor "numGroundKills"
|
||||
* @anchor "numHumanKills"
|
||||
* @anchor "numNavalKills"
|
||||
* @anchor "numCaptures"
|
||||
* @anchor "numDamage"
|
||||
* @anchor "numCritical"
|
||||
* @anchor "numHit"
|
||||
* @anchor "numAssist"
|
||||
* @anchor "numBattleTime"
|
||||
* @anchor "numMission"
|
||||
* @anchor "numTotal"
|
||||
* @anchor "numAwardDamage"
|
||||
* @anchor "numAirSevereDamage"
|
||||
* @anchor "numShipSevereDamage"
|
||||
* @anchor "noBonusWp"
|
||||
* @anchor "expInvestModuleTotal"
|
||||
* @anchor "expInvestUnitTotal"
|
||||
* @anchor "ucavLaunch"
|
||||
* @anchor "prepareSupportPlane"
|
||||
*/
|
||||
#define LMP_STAT_OFF_SESSION_TIME 0x0000u
|
||||
#define LMP_STAT_OFF_BATTLE_TIME 0x0008u
|
||||
#define LMP_STAT_BKT_AIR_KILLS 0x0110u
|
||||
#define LMP_STAT_BKT_GROUND_KILLS 0x0150u
|
||||
#define LMP_STAT_BKT_HUMAN_KILLS 0x01d0u
|
||||
#define LMP_STAT_BKT_NAVAL_KILLS 0x0250u
|
||||
#define LMP_STAT_BKT_CAPTURES 0x0350u
|
||||
#define LMP_STAT_BKT_DAMAGE 0x03d0u
|
||||
#define LMP_STAT_BKT_CRITICAL 0x0410u
|
||||
#define LMP_STAT_BKT_HIT 0x0450u
|
||||
#define LMP_STAT_BKT_ASSIST 0x0490u
|
||||
#define LMP_STAT_BKT_BATTLE_TIME 0x04d0u
|
||||
#define LMP_STAT_BKT_MISSION 0x0550u
|
||||
#define LMP_STAT_BKT_TOTAL 0x0650u
|
||||
#define LMP_STAT_BKT_AWARD_DAMAGE 0x0790u
|
||||
#define LMP_STAT_BKT_AIR_SEVERE 0x0810u
|
||||
#define LMP_STAT_BKT_SHIP_SEVERE 0x0850u
|
||||
#define LMP_USTAT_OFF_SCORE 0x0a5cu
|
||||
#define LMP_USTAT_OFF_EXP_MOD 0x0a78u
|
||||
#define LMP_USTAT_OFF_EXP_MOD_TOTAL 0x0a7cu
|
||||
#define LMP_USTAT_OFF_EXP_UNIT 0x0a80u
|
||||
#define LMP_USTAT_OFF_EXP_UNIT_TOTAL 0x0a84u
|
||||
#define LMP_SSTAT_OFF_ACTIVITY 0x0aa4u
|
||||
#define LMP_SSTAT_OFF_EXP_FREE 0x0ae0u
|
||||
#define LMP_SSTAT_OFF_RESULT 0x0ae4u
|
||||
|
||||
#define LMP_BKT_OFF_COUNT 0x00u
|
||||
#define LMP_BKT_OFF_EXP 0x04u
|
||||
#define LMP_BKT_OFF_WP 0x08u
|
||||
#define LMP_BKT_OFF_RAW_EXP 0x0cu
|
||||
#define LMP_BKT_OFF_RAW_WP 0x10u
|
||||
#define LMP_BKT_OFF_NO_BONUS_EXP 0x14u
|
||||
#define LMP_BKT_OFF_NO_BONUS_WP 0x18u
|
||||
|
||||
/* @rip_check LMP_SIG_DISABLED_SLOTS_MASK + 0x02 : 48 83 3d */
|
||||
/* @rip_check LMP_SIG_DISABLED_SLOTS_MASK + 0x0c : 48 8b 0d */
|
||||
/* @rip_check LMP_SIG_DISABLED_SLOTS_MASK + 0x1f : 48 8b 0d */
|
||||
/* @rip_check LMP_SIG_DO_RESPAWN_PLAYER + 0x7d : 48 8b 15 */
|
||||
/* @rip_check LMP_SIG_SQ_LOCAL_COUNTRY + 0x1c : 48 8d 0d */
|
||||
/* @rip_check LMP_SIG_REFL_DTOR + 0x8b : 48 8b 0d */
|
||||
/* @rip_check LMP_SIG_GET_PLAYER_COUNTRY + 0x2e : 44 3b 15 */
|
||||
/* @rip_check LMP_SIG_GET_PLAYER_COUNTRY + 0x37 : 4c 8b 1d */
|
||||
/* @rip_check LMP_SIG_IGROUND_ON_DEAD + 0xa19 : 48 8b 0d */
|
||||
/* @rip_check LMP_SIG_DATABLOCK_SET_FROM + 0x25 : e8 */
|
||||
/* @rip_check LMP_SIG_CALLER_CAPTURE_ZONE + 0x6b : e8 */
|
||||
/* @rip_check LMP_SIG_CALLER_HIT_CRIT + 0x59 : e8 */
|
||||
/* @rip_check LMP_SIG_CALLER_SEVERE_DMG + 0x2f : e8 */
|
||||
/* @rip_check LMP_SIG_CALLER_NAVAL_DMG + 0x67 : e8 */
|
||||
|
||||
#define LMP_SIG_DISABLED_SLOTS_MASK "31 c0 48 83 3d ?? ?? ?? ?? 00 74 ?? 48 8b 0d ?? ?? ?? ?? 0f b6 89 f3 00 00 00 f6 c1 01 74 ?? 48 8b 0d ?? ?? ?? ?? 48 85 c9 74 ?? 8b 81 a0 04 00 00 0b 81 d0 04 00 00 c3"
|
||||
#define LMP_SIG_DO_RESPAWN_PLAYER "56 57 53 48 81 ec 40 01 00 00 44 0f 29 84 24 30 01 00 00 0f 29 bc 24 20 01 00 00 0f 29 b4 24 10 01 00 00 48 8b 91 e0 03 00 00 48 c7 c0 ff ff ff ff 48 85 d2 0f 84 ?? ?? ?? ?? 8b 92 f0 00 00 00 83 fa 01 0f 85 ?? ?? ?? ?? f3 0f 10 81 e4 06 00 00 0f 57 c9 0f 2e c1 0f 83 ?? ?? ?? ?? 4c 8b 05 ?? ?? ?? ?? 40 b6 01 4d 85 c0 0f 84 ?? ?? ?? ?? f6 05 ?? ?? ?? ?? 04 0f 84 ?? ?? ?? ?? 48 8b 15 ?? ?? ?? ?? 48 85 d2 0f 84 ?? ?? ?? ??"
|
||||
#define LMP_SIG_SEM_CHANGE_AIRCRAFT_SEND "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec f8 01 00 00 44 0f 29 84 24 e0 01 00 00 0f 29 bc 24 d0 01 00 00 0f 29 b4 24 c0 01 00 00 4c 89 cf 4c 89 c3 49 89 d7 48 89 ce 8b 05 ?? ?? ?? ?? 65 48 8b 0c 25 58 00 00 00"
|
||||
#define LMP_SIG_GUI_STATE_UPDATE "56 57 48 83 ec 48 48 89 ce f3 0f 10 41 08 f3 0f 58 c1 f3 0f 11 41 08 f3 0f 10 51 10 0f 57 c0 0f 2e c2 73 ?? f3 0f 5c d1 f3 0f 11 56 10 48 8b 0d ?? ?? ?? ?? b0 01 0f 2e 81 e4 06 00 00 76 ??"
|
||||
#define LMP_SIG_MPLAYER_INIT_MATCHING "41 56 56 57 55 53 48 81 ec e0 00 00 00 48 89 d7 48 89 ce 48 89 91 90 0c 00 00 48 8d 8c 24 88 00 00 00 0f 57 c0 0f 11 84 24 b8 00 00 00 0f 11 84 24 a8 00 00 00 0f 11 84 24 98 00 00 00"
|
||||
#define LMP_SIG_GET_PLAYER_COUNTRY "56 48 83 ec 40 4c 89 c0 4c 8b 05 ?? ?? ?? ?? 4d 85 c0 0f 84 ?? ?? ?? ?? 45 31 d2 41 80 78 61 00 44 0f 44 d2 81 fa fa 00 00 00 44 0f 45 d2 44 3b 15 ?? ?? ?? ?? 73 ?? 4c 8b 1d ?? ?? ?? ??"
|
||||
#define LMP_SIG_SQ_LOCAL_COUNTRY "41 56 56 57 53 48 83 ec 68 48 89 ce 48 8b 05 ?? ?? ?? ?? 48 85 c0 74 ?? 0f b6 50 08 48 8d 0d ?? ?? ?? ?? 4c 8d 44 24 20 41 b9 40 00 00 00 e8 ?? ?? ?? ?? 48 89 c7"
|
||||
#define LMP_SIG_REFL_CTOR "56 48 83 ec 50 0f 29 74 24 40 48 89 ce 66 c7 41 08 ff ff c7 41 0c ff ff ff ff 0f 57 f6 0f 11 71 10 c7 41 20 44 4e 45 54 0f 11 71 28 0f 11 71 38"
|
||||
#define LMP_SIG_REFL_DTOR "56 57 53 48 83 ec 40 48 89 ce 48 8d 05 ?? ?? ?? ?? 48 89 01 48 8b 89 b0 01 00 00 48 85 c9 74 ?? e8 ?? ?? ?? ?? 48 8b be 90 01 00 00 48 8b 9e 98 01 00 00 48 39 df"
|
||||
#define LMP_SIG_UNIT_CHANGE_AIRCRAFT "41 57 41 56 56 57 55 53 48 81 ec 88 00 00 00 48 89 ce 8b 81 90 00 00 00 a8 10 75 ?? 80 be 1a 0f 00 00 00 75 ?? 48 8b 05 ?? ?? ?? ?? 0f b6 80 f3 00 00 00 0f b6 0d ?? ?? ?? ?? 08 c8 a8 01 74 ??"
|
||||
#define LMP_SIG_AIRCRAFT_CHANGE_RESULT "41 57 41 56 56 57 53 48 83 ec 50 41 89 d0 48 89 ce 48 81 c1 78 f5 00 00 48 89 f2 e8 ?? ?? ?? ?? 84 c0 0f 84 ?? ?? ?? ?? 48 8b 9e 78 f5 00 00 48 85 db 48 8d 3d ?? ?? ?? ?? 48 0f 44 df"
|
||||
#define LMP_SIG_DATABLOCK_SET_FROM "41 57 41 56 41 55 41 54 56 57 55 53 48 83 ec 48 48 89 d7 48 89 ce 66 2e 0f 1f 84 00 00 00 00 00 b9 90 00 00 00 e8 ?? ?? ?? ?? 48 85 c0 75 ?? 48 8b 05 ?? ?? ?? ??"
|
||||
#define LMP_SIG_DATABLOCK_DTOR "41 57 41 56 41 54 56 57 53 48 83 ec 38 0f 29 74 24 20 48 8b 41 18"
|
||||
#define LMP_SIG_DATABLOCK_GET_STR "48 83 ec 28 4c 89 44 24 20 4c 8d 44 24 20 e8 ?? ?? ?? ?? 90 48 83 c4 28 c3 cc cc cc cc cc cc cc 41 57"
|
||||
#define LMP_SIG_DATABLOCK_GET_REAL "48 83 ec 28 f3 0f 11 54 24 24 4c 8d 44 24 24 e8 ?? ?? ?? ?? 90 48 83 c4 28 c3 cc cc cc cc cc cc 56 57 53 48 83 ec 30 48 89 d7 48 89 ce 48 8d 15"
|
||||
#define LMP_SIG_MP_CONSTRUCT_LOCAL "56 57 53 48 83 ec 60 48 89 ce 48 81 c1 f8 00 00 00 e8 ?? ?? ?? ?? 66 c7 46 60 01 01"
|
||||
#define LMP_SIG_MP_INIT_CHAT "41 57 41 56 41 54 56 57 53 48 83 ec 48 48 89 d7 48 89 ce 48 8b 05 ?? ?? ?? ?? 48 85 c0 74 ?? c6 00 01 48 8b 9e 00 02 00 00"
|
||||
#define LMP_SIG_IGROUND_AWARD_ASSISTS "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec a8 01 00 00 44 0f 29 94 24 90 01 00 00 44 0f 29 8c 24 80 01 00 00 44 0f 29 84 24 70 01 00 00 0f 29 bc 24 60 01 00 00 0f 29 b4 24 50 01 00 00 48 89 ce 48 8b 01 48 8d 54 24 28 41 b0 01 ff 90 98 04 00 00"
|
||||
#define LMP_SIG_BULLET_VEC_ASSIGN "41 57 41 56 41 55 41 54 56 57 55 53 48 83 ec 58 4c 89 c5 49 89 d7 48 89 ce 4c 89 c3 48 29 d3 4c 8b 01 48 8b 41 10 4c 29 c0 48 39 c3 0f 86 ?? ?? ?? ?? 48 89 d9"
|
||||
#define LMP_SIG_SET_PLAYER_GUI_STATE "41 57 41 56 41 54 56 57 55 53 48 83 ec 40 89 d6 48 8b 15 ?? ?? ?? ?? 48 85 d2 74 ?? 80 7a 60 00 0f 84 ?? ?? ?? ?? 85 c9 78 ?? 31 c0 80 7a 61 00 0f 44 c1 81 f9 fa 00 00 00 0f 45 c1 eb ?? 89 c8"
|
||||
#define LMP_SIG_GET_UNIT_BY_EID "39 0d ?? ?? ?? ?? 74 2f 89 ca c1 ea 0a 3b 15 ?? ?? ?? ??"
|
||||
#define LMP_SIG_SET_OWNING_MPLAYER "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 98 00 00 00 44 89 c3 48 89 d7 48 89 ce 48 85 d2"
|
||||
#define LMP_SIG_GET_DECALS_BLK "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 88 00 00 00 44 0f 29 44 24 70 0f 29 7c 24 60 0f 29 74 24 50 4d 89 cf"
|
||||
#define LMP_SIG_GET_ATTACHABLES_BLK "41 57 41 56 41 55 41 54 56 57 55 53 48 83 ec 38 48 89 d7 4d 85 c0"
|
||||
#define LMP_SIG_STR_HASH_FNV1 "41 56 56 57 53 49 89 d0 49 ba db 28 b4 a0 d1 7e 03 e7 48 83 fa 10 77 76"
|
||||
#define LMP_SIG_NAMEMAP_ADD_NAME_ID "41 57 41 56 41 55 41 54 56 57 55 53 48 83 ec 38 44 89 cf 48 89 ce 80 79 4b 00"
|
||||
#define LMP_SIG_CREW_SKILLS_INIT "41 56 56 57 55 53 48 81 ec 90 00 00 00 0f 29 b4 24 80 00 00 00 0f 28 f3"
|
||||
#define LMP_SIG_UCAV_LAUNCH "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 18 02 00 00 0f 29 bc 24 00 02 00 00 0f 29 b4 24 f0 01 00 00 48 8b 05 ?? ?? ?? ??"
|
||||
#define LMP_SIG_IGROUND_ON_DEAD "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec a8 01 00 00 44 0f 29 8c 24 90 01 00 00 44 0f 29 84 24 80 01 00 00 0f 29 bc 24 70 01 00 00 0f 29 b4 24 60 01 00 00 89 d3"
|
||||
#define LMP_SIG_ON_UNIT_DEAD_ONCE "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 98 01 00 00 44 0f 29 84 24 80 01 00 00 0f 29 bc 24 70 01 00 00 0f 29 b4 24 60 01 00 00 80 b9 58 30 00 00 00 0f 85 ?? ?? ?? ?? 48 89 ce 48 8d 54 24 38 e8 ?? ?? ?? ?? 66 83 7c 24 38 ff"
|
||||
#define LMP_SIG_MPLAYER_ADD_SCORE "41 57 41 56 56 57 55 53 48 81 ec 88 00 00 00 0f 29 7c 24 70 0f 29 74 24 60 48 89 ce 44 89 c0 f3 0f 2a 84 81 fc 08 00 00 0f 28 f9 f3 0f 58 c1 f3 0f 2c c8 89 8c 86 fc 08 00 00"
|
||||
#define LMP_SIG_NET_MARK_DIRTY "56 57 53 48 83 ec 40 81 7a 20 44 4e 45 54 0f 85 ?? ?? ?? ?? 48 89 ce 0f b7 41 02 a8 02 75 ?? f6 42 48 02 75 ?? a8 01 75 ?? 4c 89 c7 83 c8 01 66 89 46 02"
|
||||
#define LMP_SIG_HUD_ADD_SCORE_MSG "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 38 01 00 00 45 89 c5 41 8d 45 fd"
|
||||
#define LMP_SIG_SESSION_STATS_RESET "41 56 56 57 53 48 83 ec 48 0f 29 74 24 30 48 89 ce 48 8d 05 ?? ?? ?? ?? 48 89 44 24 28"
|
||||
#define LMP_SIG_SESSION_STATS_GET_UNIT "56 57 53 48 83 ec 40 48 89 d6 48 89 cf 48 89 54 24 30"
|
||||
#define LMP_SIG_START_ACTUALIZE_CLIENT "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 38 01 00 00 0f 29 b4 24 20 01 00 00 83 b9 80 02 01 00 ff"
|
||||
#define LMP_SIG_DISPATCH_ASSIST "41 57 41 56 41 55 41 54 56 57 55 53 48 83 ec 78 0f 29 7c 24 60 0f 29 74 24 50 0f 28 f3 4c 89 c6 48 89 d7 48 89 cb 48 8b 05 ?? ?? ?? ?? 48 85 c9 7e ?? 48 85 c0"
|
||||
#define LMP_SIG_CALLER_CAPTURE_ZONE "41 57 41 56 41 55 41 54 56 57 55 53 48 83 ec 38 44 0f b7 72 02 44 8b 7a 04 4c 8b 62 08 4c 8b 6a 18 49 8d 85 88 06 00 00 48 89 44 24 30 49 8d 85 50 06 00 00 48 89 44 24 28 eb ?? 48 8b 90 08 0e 00 00 89 d1 83 e1 01 0b 0d ?? ?? ?? ?? 3b 88 14 0e 00 00 0f 85 ?? ?? ?? ?? 48 83 e2 fe 48 8b 82 98 0f 00 00 48 8b 88 b8 00 00 00 e8 ?? ?? ?? ??"
|
||||
#define LMP_SIG_CALLER_HIT_CRIT "8b 0d ?? ?? ?? ?? f7 c1 00 00 08 00 75 ?? f7 c1 00 00 00 01 75 ?? 0f b6 8f 10 10 00 00 39 4e 1c 74 ?? 41 20 c0 0f b6 86 49 01 00 00 0f 57 db f3 0f 5f 9e 30 01 00 00 48 8b 4e 58 85 ed f3 0f 5d 1d ?? ?? ?? ?? 88 44 24 30 0f 9f 44 24 28 44 88 44 24 20 48 89 fa 49 89 f0 e8 ?? ?? ?? ??"
|
||||
#define LMP_SIG_CALLER_SEVERE_DMG "66 83 be b0 06 00 00 ff 0f 85 ?? ?? ?? ?? 48 89 f1 e8 ?? ?? ?? ?? 84 c0 0f 84 ?? ?? ?? ?? 48 8d 9e b0 06 00 00 48 8b 4f 58 48 89 f2 49 89 f8 e8 ?? ?? ?? ?? 48 89 f1 48 89 fa e8 ?? ?? ?? ?? 0f b6 ae d4 06 00 00"
|
||||
#define LMP_SIG_CALLER_NAVAL_DMG "66 83 b9 90 0f 00 00 01 77 ?? 66 83 ff ff 74 ?? 0f b7 c7 0f 57 d2 f3 0f 2a d0 f3 0f 59 15 ?? ?? ?? ?? eb ?? f3 0f 10 15 ?? ?? ?? ?? 48 8b 94 24 c0 03 00 00 0f b6 7c 24 5b 41 89 f9 e8 ?? ?? ?? ?? 0f 57 c0 0f 2e f0 0f 96 c0 40 08 f8 a8 01 75 ?? 48 8b 96 e8 0a 00 00 4c 8b 84 24 c0 03 00 00 49 8b 48 58 0f 28 de e8 ?? ?? ?? ??"
|
||||
#define LMP_SIG_COUNT_ACTIVE_PLAYERS "41 57 41 56 41 54 56 57 53 48 83 ec 38 89 cf 80 f2 01 0f b6 c2 c1 e0 0a 83 c8 3a"
|
||||
#define LMP_SIG_IS_SLOT_READY_AT_HOST "41 56 56 57 55 53 48 81 ec a0 00 00 00 0f 29 b4 24 90 00 00 00 44 89 c3 48 89 d6 48 83 3d"
|
||||
@@ -0,0 +1,232 @@
|
||||
/*
|
||||
* LocalMP player team alignment, AI MPlayer <-> Unit ownership binding,
|
||||
* asynchronous aircraftChangeResultFromHost handshake, and spawn-only ledger activation.
|
||||
*/
|
||||
#include "hooks.h"
|
||||
#include "hook_config.h"
|
||||
#include "local_mp_internal.h"
|
||||
#include "local_mp_offsets.h"
|
||||
|
||||
#include "MinHook.h"
|
||||
|
||||
#include <string.h>
|
||||
|
||||
typedef void (__fastcall *GuiStateUpdateFn)(uint8_t *gui_state_obj, float dt);
|
||||
typedef void (__fastcall *MPlayerInitFromMatchingFn)(uint8_t *mplayer, uint8_t *info, uint64_t uid);
|
||||
typedef int64_t (__fastcall *DoRespawnPlayerFn)(void *app);
|
||||
typedef uint8_t (__fastcall *IsSlotReadyAtHostFn)(int32_t slot_id, const char *unit_name, uint8_t debug);
|
||||
|
||||
static GuiStateUpdateFn orig_gui_state_update;
|
||||
static MPlayerInitFromMatchingFn orig_mplayer_init_matching;
|
||||
static DoRespawnPlayerFn orig_do_respawn;
|
||||
static IsSlotReadyAtHostFn orig_is_slot_ready_at_host;
|
||||
|
||||
static int g_accept_pending = 0;
|
||||
static int g_respawn_dispatched = 0;
|
||||
static int32_t g_pending_slot_id = -1;
|
||||
static int32_t g_pending_spare_type = -1;
|
||||
|
||||
void local_mp_players_queue_spawn(int32_t slot_id, int32_t spare_type, int is_silent)
|
||||
{
|
||||
if (!is_silent || g_pending_slot_id < 0) {
|
||||
g_pending_slot_id = slot_id;
|
||||
g_pending_spare_type = spare_type;
|
||||
}
|
||||
if (!is_silent)
|
||||
g_respawn_dispatched = 0;
|
||||
g_accept_pending = 1;
|
||||
}
|
||||
|
||||
static void bind_ai_mplayer_units(void)
|
||||
{
|
||||
uint8_t **table = g_local_mp_player_table ? *g_local_mp_player_table : NULL;
|
||||
uint32_t count = g_local_mp_player_count ? *g_local_mp_player_count : 0;
|
||||
uint32_t i;
|
||||
|
||||
if (table == NULL || count <= 1 || !g_lmp_get_unit_by_eid || !g_lmp_set_owning_mplayer)
|
||||
return;
|
||||
|
||||
for (i = 1; i < count; i++) {
|
||||
uint8_t *mp = table[i];
|
||||
uint32_t eid;
|
||||
uint8_t *unit;
|
||||
|
||||
if (mp == NULL)
|
||||
continue;
|
||||
eid = *(uint32_t *)(mp + LMP_MP_OFF_UNIT_EID);
|
||||
if (eid == 0)
|
||||
continue;
|
||||
unit = (uint8_t *)g_lmp_get_unit_by_eid(eid);
|
||||
if (unit != NULL && *(uint8_t **)(unit + LMP_UNIT_OFF_MPLAYER) != mp)
|
||||
g_lmp_set_owning_mplayer(unit, mp, 1, 1);
|
||||
}
|
||||
}
|
||||
|
||||
static int32_t resolve_configured_player_team(void)
|
||||
{
|
||||
const char *team_str;
|
||||
char country_buf[64];
|
||||
uint8_t saved_arcade;
|
||||
const char *short_country;
|
||||
const char *axis_country;
|
||||
const char *allies_country;
|
||||
|
||||
if (g_lmp_datablock_get_str != NULL) {
|
||||
team_str = g_lmp_datablock_get_str(
|
||||
g_local_mp_mission_settings + LMP_MIS_OFF_CUSTOM_BOTS, "wtoPlayerTeam", "");
|
||||
if (team_str != NULL && strcmp(team_str, "1") == 0)
|
||||
return 1;
|
||||
if (team_str != NULL && strcmp(team_str, "2") == 0)
|
||||
return 2;
|
||||
}
|
||||
|
||||
memset(country_buf, 0, sizeof(country_buf));
|
||||
saved_arcade = g_local_mp_mission_settings[LMP_MIS_OFF_ARCADE_COUNTRY];
|
||||
g_local_mp_mission_settings[LMP_MIS_OFF_ARCADE_COUNTRY] = 1;
|
||||
g_lmp_get_player_country(g_local_mp_mission_settings, 0, country_buf, (int32_t)sizeof(country_buf));
|
||||
g_local_mp_mission_settings[LMP_MIS_OFF_ARCADE_COUNTRY] = saved_arcade;
|
||||
|
||||
short_country = strncmp(country_buf, "country_", 8) == 0 ? country_buf + 8 : country_buf;
|
||||
axis_country = *(const char **)(g_local_mp_mission_settings + LMP_MIS_OFF_AXIS_COUNTRY);
|
||||
allies_country = *(const char **)(g_local_mp_mission_settings + LMP_MIS_OFF_ALLIES_COUNTRY);
|
||||
if (short_country[0] != '\0') {
|
||||
if (axis_country != NULL && strcmp(short_country, axis_country) == 0)
|
||||
return 2;
|
||||
if (allies_country != NULL && strcmp(short_country, allies_country) == 0)
|
||||
return 1;
|
||||
}
|
||||
return 0;
|
||||
}
|
||||
|
||||
static void __fastcall hook_mplayer_init_from_matching(uint8_t *mplayer, uint8_t *info, uint64_t uid)
|
||||
{
|
||||
if (local_mp_is_host() && mplayer != NULL && info != NULL &&
|
||||
g_local_mp_mission_settings != NULL && g_lmp_get_player_country != NULL &&
|
||||
local_mp_is_local_mplayer(mplayer)) {
|
||||
int32_t desired_team = resolve_configured_player_team();
|
||||
if (desired_team == 1 || desired_team == 2)
|
||||
*(int32_t *)(info + LMP_MATCH_INFO_OFF_TEAM) = desired_team;
|
||||
local_mp_ledger_reset();
|
||||
log_line("local_mp: initialized local player team=%d",
|
||||
(int)(*(int32_t *)(info + LMP_MATCH_INFO_OFF_TEAM)));
|
||||
}
|
||||
orig_mplayer_init_matching(mplayer, info, uid);
|
||||
}
|
||||
|
||||
static void consume_pending_slot_if_spawned(uint8_t *mplayer)
|
||||
{
|
||||
const char *hero_name;
|
||||
|
||||
if (!g_respawn_dispatched || mplayer == NULL)
|
||||
return;
|
||||
if (mplayer[LMP_MP_OFF_GUI_STATE] == LMP_GUI_STATE_CA_SELECT) {
|
||||
g_respawn_dispatched = 0;
|
||||
return;
|
||||
}
|
||||
if (mplayer[LMP_MP_OFF_GUI_STATE] != LMP_GUI_STATE_PILOT_CONTROL)
|
||||
return;
|
||||
|
||||
g_respawn_dispatched = 0;
|
||||
hero_name = g_local_mp_hero ? local_mp_unit_name(*g_local_mp_hero) : NULL;
|
||||
if (hero_name != NULL)
|
||||
local_mp_ledger_activate_unit(hero_name);
|
||||
|
||||
if (g_pending_slot_id >= 0 && g_pending_slot_id < 32) {
|
||||
uint32_t bit = 1u << (uint32_t)g_pending_slot_id;
|
||||
if (g_pending_spare_type < 0)
|
||||
*(uint32_t *)(mplayer + LMP_MP_OFF_BROKEN_SLOTS_MASK) |= bit;
|
||||
else
|
||||
*(uint32_t *)(mplayer + LMP_MP_OFF_USED_SPARES_MASK) |= bit;
|
||||
log_line("local_mp: spawned unit='%s' slot=%d spare=%d brokenMask=0x%x spareMask=0x%x",
|
||||
hero_name ? hero_name : "", (int)g_pending_slot_id, (int)g_pending_spare_type,
|
||||
*(uint32_t *)(mplayer + LMP_MP_OFF_BROKEN_SLOTS_MASK),
|
||||
*(uint32_t *)(mplayer + LMP_MP_OFF_USED_SPARES_MASK));
|
||||
g_pending_slot_id = -1;
|
||||
}
|
||||
}
|
||||
|
||||
static void __fastcall hook_gui_state_update(uint8_t *gui_state_obj, float dt)
|
||||
{
|
||||
uint8_t *mplayer;
|
||||
|
||||
orig_gui_state_update(gui_state_obj, dt);
|
||||
|
||||
if (!local_mp_is_host()) {
|
||||
g_accept_pending = 0;
|
||||
g_respawn_dispatched = 0;
|
||||
g_pending_slot_id = -1;
|
||||
return;
|
||||
}
|
||||
|
||||
bind_ai_mplayer_units();
|
||||
mplayer = g_local_mp_mplayer ? *g_local_mp_mplayer : NULL;
|
||||
consume_pending_slot_if_spawned(mplayer);
|
||||
|
||||
if (g_accept_pending && gui_state_obj != NULL) {
|
||||
uint8_t *econ_state = local_mp_econ_state();
|
||||
if (mplayer != NULL && econ_state != NULL &&
|
||||
mplayer[LMP_MP_OFF_GUI_STATE] == LMP_GUI_STATE_CA_READY &&
|
||||
*(int32_t *)gui_state_obj == LMP_GUI_STATE_CA_READY) {
|
||||
g_accept_pending = 0;
|
||||
*(float *)(gui_state_obj + 0x10) = 0.0f;
|
||||
g_lmp_aircraft_change_result(econ_state, 0);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
static int64_t __fastcall hook_do_respawn_player(void *app)
|
||||
{
|
||||
uint8_t *mplayer;
|
||||
int64_t result;
|
||||
|
||||
if (!local_mp_is_host())
|
||||
return orig_do_respawn(app);
|
||||
|
||||
mplayer = g_local_mp_mplayer ? *g_local_mp_mplayer : NULL;
|
||||
if (mplayer != NULL && mplayer[LMP_MP_OFF_GUI_STATE] != LMP_GUI_STATE_PILOT_CONTROL)
|
||||
g_respawn_dispatched = 1;
|
||||
|
||||
result = orig_do_respawn(app);
|
||||
consume_pending_slot_if_spawned(mplayer);
|
||||
bind_ai_mplayer_units();
|
||||
return result;
|
||||
}
|
||||
|
||||
static uint8_t __fastcall hook_is_slot_ready_at_host(int32_t slot_id, const char *unit_name, uint8_t debug)
|
||||
{
|
||||
uint8_t *mplayer;
|
||||
|
||||
if (!local_mp_is_host())
|
||||
return orig_is_slot_ready_at_host(slot_id, unit_name, debug);
|
||||
if (orig_is_slot_ready_at_host(slot_id, unit_name, debug))
|
||||
return 1;
|
||||
if (slot_id < 0 || slot_id >= 32 || unit_name == NULL || unit_name[0] == '\0')
|
||||
return 0;
|
||||
mplayer = g_local_mp_mplayer ? *g_local_mp_mplayer : NULL;
|
||||
if (mplayer == NULL)
|
||||
return 1;
|
||||
return (*(uint32_t *)(mplayer + LMP_MP_OFF_BROKEN_SLOTS_MASK) & (1u << (uint32_t)slot_id)) == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
int install_local_mp_player_hooks(const uint8_t *text, size_t text_size, uint8_t *p_do_respawn)
|
||||
{
|
||||
uint8_t *p_gui_update = local_mp_scan_unique(text, text_size, "GuiState::update", LMP_SIG_GUI_STATE_UPDATE);
|
||||
uint8_t *p_mp_init = local_mp_scan_unique(text, text_size, "MPlayer::initFromMatching", LMP_SIG_MPLAYER_INIT_MATCHING);
|
||||
uint8_t *p_slot_ready = local_mp_scan_unique(text, text_size, "is_crew_slot_was_ready_at_host", LMP_SIG_IS_SLOT_READY_AT_HOST);
|
||||
|
||||
if (!p_gui_update || !p_mp_init || !p_do_respawn || !p_slot_ready)
|
||||
return 0;
|
||||
|
||||
if (MH_CreateHook(p_gui_update, (void *)&hook_gui_state_update, (void **)&orig_gui_state_update) != MH_OK ||
|
||||
MH_EnableHook(p_gui_update) != MH_OK ||
|
||||
MH_CreateHook(p_mp_init, (void *)&hook_mplayer_init_from_matching, (void **)&orig_mplayer_init_matching) != MH_OK ||
|
||||
MH_EnableHook(p_mp_init) != MH_OK ||
|
||||
MH_CreateHook(p_do_respawn, (void *)&hook_do_respawn_player, (void **)&orig_do_respawn) != MH_OK ||
|
||||
MH_EnableHook(p_do_respawn) != MH_OK ||
|
||||
MH_CreateHook(p_slot_ready, (void *)&hook_is_slot_ready_at_host, (void **)&orig_is_slot_ready_at_host) != MH_OK ||
|
||||
MH_EnableHook(p_slot_ready) != MH_OK) {
|
||||
log_line("local_mp: failed to install player state hooks");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
}
|
||||
Reference in new issue
Block a user