Credit completed zone captures to the units counted by the mission engine and send the local capture fact through the existing settlement flow. Filter hit markers and shell-change hints using the actual attacker and active view. TypeScript checks and the MSVC build passed. Verified exe, Quirrel, and native patches on 2.61.0.37, 2.61.0.58, 2.61.0.60, and 2.61.0.64. Rebuilt the .58 and .64 copies and verified local service health on .58. In-game verification is pending.
109 lines
4.0 KiB
C
109 lines
4.0 KiB
C
/* Credit completed captures using the mission engine's own unit eligibility checks. */
|
|
#include "hook_config.h"
|
|
#include "local_mp_internal.h"
|
|
#include "local_mp_offsets.h"
|
|
|
|
#include <intrin.h>
|
|
#include <windows.h>
|
|
|
|
typedef void (__fastcall *SetZoneOwnerFn)(uint8_t *zone, int32_t team);
|
|
typedef float (__fastcall *TeamCapturePowerFn)(int32_t team, uint8_t *zone, int32_t *count);
|
|
typedef float (__fastcall *UnitCapturePowerFn)(uint8_t *zone, const uint8_t *unit);
|
|
|
|
typedef struct CaptureAward {
|
|
uint8_t *player;
|
|
const char *unit_name;
|
|
float power;
|
|
float score;
|
|
} CaptureAward;
|
|
|
|
typedef struct CaptureScan {
|
|
const uint8_t *zone;
|
|
int32_t team;
|
|
CaptureAward awards[UINT8_MAX + 1];
|
|
} CaptureScan;
|
|
|
|
static __declspec(thread) CaptureScan *active_scan;
|
|
static SetZoneOwnerFn original_set_owner;
|
|
static UnitCapturePowerFn original_unit_power;
|
|
static uintptr_t cta_end;
|
|
|
|
static float __fastcall hook_unit_power(uint8_t *zone, const uint8_t *unit)
|
|
{
|
|
float power = original_unit_power(zone, unit);
|
|
CaptureScan *scan = active_scan;
|
|
if (scan == NULL || scan->zone != zone || unit == NULL || !(power > 0.0f))
|
|
return power;
|
|
|
|
uint8_t *player = *(uint8_t *const *)(unit + LMP_UNIT_OFF_MPLAYER);
|
|
if (player == NULL || player[LMP_MP_OFF_TEAM] != scan->team)
|
|
return power;
|
|
|
|
CaptureAward *award = &scan->awards[player[LMP_MP_OFF_PID]];
|
|
if (power > award->power) {
|
|
award->player = player;
|
|
award->unit_name = local_mp_unit_name(unit);
|
|
award->power = power;
|
|
award->score = local_mp_event_score("capture", unit, 1);
|
|
}
|
|
return power;
|
|
}
|
|
|
|
static int is_capture_completion(uintptr_t return_address)
|
|
{
|
|
return return_address == (uintptr_t)g_lmp.capture_complete_call + LMP_REL32_CALL_SIZE ||
|
|
(return_address >= (uintptr_t)g_lmp.capture_cta_logic && return_address < cta_end);
|
|
}
|
|
|
|
static void credit_capture(const CaptureAward *award)
|
|
{
|
|
uint8_t *player = award->player;
|
|
local_mp_inc_mplayer_stat(player, LMP_MP_OFF_CAPTURE_ZONE);
|
|
local_mp_add_personal_score(player, award->score, LMP_EXP_EVENT_CAPTURE_ZONE);
|
|
local_mp_mark_mplayer_dirty(player);
|
|
if (local_mp_is_local_mplayer(player))
|
|
local_mp_report_capture(award->unit_name);
|
|
}
|
|
|
|
static void __fastcall hook_set_owner(uint8_t *zone, int32_t team)
|
|
{
|
|
if (!local_mp_is_host() || !is_capture_completion((uintptr_t)_ReturnAddress()) ||
|
|
(team != 1 && team != 2) || zone[g_lmp.capture_owner] == team) {
|
|
original_set_owner(zone, team);
|
|
return;
|
|
}
|
|
|
|
/* Run the same side's eligibility walk immediately before the ownership commit. A player
|
|
can have several eligible units in that walk, so credit their strongest one once. */
|
|
CaptureScan scan = { .zone = zone, .team = team };
|
|
CaptureScan *previous = active_scan;
|
|
int32_t count = 0;
|
|
active_scan = &scan;
|
|
((TeamCapturePowerFn)g_lmp.capture_team_power)(team, zone, &count);
|
|
active_scan = previous;
|
|
|
|
original_set_owner(zone, team);
|
|
if (zone[g_lmp.capture_owner] != team)
|
|
return;
|
|
for (size_t pid = 0; pid < sizeof(scan.awards) / sizeof(scan.awards[0]); ++pid) {
|
|
if (scan.awards[pid].player != NULL)
|
|
credit_capture(&scan.awards[pid]);
|
|
}
|
|
}
|
|
|
|
int install_local_mp_capture_hooks(void)
|
|
{
|
|
DWORD64 base;
|
|
const RUNTIME_FUNCTION *cta = RtlLookupFunctionEntry((DWORD64)g_lmp.capture_cta_logic, &base, NULL);
|
|
if (cta == NULL || g_lmp.capture_complete_set_owner != g_lmp.capture_set_owner) {
|
|
log_line("local_mp: local_mp_captures skipped: inconsistent ownership call sites");
|
|
return 0;
|
|
}
|
|
cta_end = (uintptr_t)(base + cta->EndAddress);
|
|
const LocalMpHookSpec hooks[] = {
|
|
{ "capture_set_owner", g_lmp.capture_set_owner, (void *)&hook_set_owner, (void **)&original_set_owner },
|
|
{ "capture_unit_power", g_lmp.capture_unit_power, (void *)&hook_unit_power, (void **)&original_unit_power },
|
|
};
|
|
return local_mp_queue_hooks("local_mp_captures", hooks, sizeof(hooks) / sizeof(hooks[0]));
|
|
}
|