merge: bring main into feat/tank-ai-nav
Takes main's mounted gun traverse limits, capture and hit feedback, LocalMP air AI sync, mod tech tree insertions and launcher changes. Conflicts resolved: - wto_ai_runtime.das: fire update runs before navigation, as on main, so a hull-aim request is driven in the same frame; navigation keeps the navmesh state and slot arguments of this branch. - wto_ai_nav_common.das: main's wto_try_hull_aim replaces the old limited-traverse pivot and uses this branch's drive command helper and stuck-watch reset. - build.ps1 and local_mp_internal.h: keep both sides' sources and declarations.
This commit is contained in:
commit
77e4806ffc
114 files changed
+4330
-623
No files matched your search
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Thread synchronization for the shared air-AI `unsortedPlanes` vector on a LocalMP host.
|
||||
*
|
||||
* Aircraft physics and AI updates run across worker threads via `threadpool::parallel_for`
|
||||
* (2.61.0.60: 0x373e51 -> 0x39f5d0 -> 0xdf52b0 -> 0xe48740 -> 0xe42db0 -> 0x31a23e0 ->
|
||||
* 0xdb07e0 -> 0x7fba00). When a bot plane finishes its behavior tree, AirAi::update tail-calls
|
||||
* TeamAiManager::addToUnsortedPlanes (0x8007b0 -> 0x80a150 on 2.61.0.60). That function locks
|
||||
* the global unit table while resolving the unit, then mutates the team's shared
|
||||
* `unsortedPlanes` dag::Vector<uint32_t> (including reserve/HeapReAlloc) without any lock.
|
||||
*
|
||||
* Online clients skip this path (isHost == 0), and retail matches rarely run 31 bot aircraft on
|
||||
* one host. In LocalMP air battles, multiple same-team bots finishing tasks right after an
|
||||
* aircraft crash race on the vector and corrupt the Windows heap (0xC0000374).
|
||||
*
|
||||
* Wrapping the function with an exclusive SRWLOCK on LocalMP hosts keeps parallel physics intact
|
||||
* while serializing mutations of `unsortedPlanes`. The target performs no callbacks or re-entrant
|
||||
* calls and acquires only the global unit-table lock after ours, so lock ordering is fixed.
|
||||
*/
|
||||
#include "hook_config.h"
|
||||
#include "local_mp_internal.h"
|
||||
#include "local_mp_values.h"
|
||||
|
||||
typedef void (__fastcall *AddUnsortedPlaneFn)(void *team_mgr, uint32_t unit_no);
|
||||
|
||||
static AddUnsortedPlaneFn orig_add_unsorted_plane;
|
||||
static SRWLOCK g_unsorted_planes_lock = SRWLOCK_INIT;
|
||||
|
||||
static void __fastcall hook_add_unsorted_plane(void *team_mgr, uint32_t unit_no)
|
||||
{
|
||||
if (!local_mp_is_host()) {
|
||||
orig_add_unsorted_plane(team_mgr, unit_no);
|
||||
return;
|
||||
}
|
||||
AcquireSRWLockExclusive(&g_unsorted_planes_lock);
|
||||
orig_add_unsorted_plane(team_mgr, unit_no);
|
||||
ReleaseSRWLockExclusive(&g_unsorted_planes_lock);
|
||||
}
|
||||
|
||||
int install_local_mp_air_ai_sync_hooks(void)
|
||||
{
|
||||
const LocalMpHookSpec hook = {
|
||||
"air_ai_add_unsorted_plane",
|
||||
g_lmp.air_ai_add_unsorted_plane,
|
||||
(void *)&hook_add_unsorted_plane,
|
||||
(void **)&orig_add_unsorted_plane,
|
||||
};
|
||||
return local_mp_queue_hooks("local_mp_air_ai_sync", &hook, 1);
|
||||
}
|
||||
@@ -58,7 +58,13 @@ const char *local_mp_unit_exp_class(const uint8_t *unit)
|
||||
return (exp_class != NULL && exp_class[0] != '\0') ? exp_class : NULL;
|
||||
}
|
||||
|
||||
void local_mp_report_award_event(const LocalMpAwardEvent *ev)
|
||||
static const char *bare_unit_name(const char *unit_name)
|
||||
{
|
||||
const char *slash = strrchr(unit_name, '/');
|
||||
return (slash != NULL && slash[1] != '\0') ? slash + 1 : unit_name;
|
||||
}
|
||||
|
||||
static void report_award_event(const LocalMpAwardEvent *ev, const char *source_unit)
|
||||
{
|
||||
__declspec(align(16)) uint8_t blk[LMP_BLK_SIZE];
|
||||
uint8_t *gsd = g_game_save_data ? *g_game_save_data : NULL;
|
||||
@@ -72,6 +78,8 @@ void local_mp_report_award_event(const LocalMpAwardEvent *ev)
|
||||
fn_blk_set_str(blk, "expClass", victim_class ? victim_class : "");
|
||||
fn_blk_set_str(blk, "victim", victim_name ? victim_name : "");
|
||||
fn_blk_set_str(blk, "messageModifier", ev->modifier ? ev->modifier : "");
|
||||
if (source_unit != NULL)
|
||||
fn_blk_set_str(blk, "unit", bare_unit_name(source_unit));
|
||||
blk_set_int(blk, "messageCode", (int32_t)ev->exp_event);
|
||||
blk_set_int(blk, "victimIsPlayer", ev->victim_is_player ? 1 : 0);
|
||||
blk_set_int(blk, "friendly", ev->friendly ? 1 : 0);
|
||||
@@ -80,6 +88,17 @@ void local_mp_report_award_event(const LocalMpAwardEvent *ev)
|
||||
fn_blk_dtor(blk);
|
||||
}
|
||||
|
||||
void local_mp_report_award_event(const LocalMpAwardEvent *ev)
|
||||
{
|
||||
report_award_event(ev, NULL);
|
||||
}
|
||||
|
||||
void local_mp_report_capture(const char *unit_name)
|
||||
{
|
||||
const LocalMpAwardEvent award = { LMP_EXP_EVENT_CAPTURE_ZONE, NULL, 0, 0, NULL, 0 };
|
||||
report_award_event(&award, unit_name);
|
||||
}
|
||||
|
||||
/* The fact behind the award killStreak_bomber_nuclear_success, which online the battle server
|
||||
* judges itself; the event carries no fields. */
|
||||
void local_mp_report_nuclear_strike(void)
|
||||
@@ -114,12 +133,11 @@ void local_mp_report_backup_spawn(const char *unit_name, int32_t slot_id, const
|
||||
{
|
||||
__declspec(align(16)) uint8_t blk[LMP_BLK_SIZE];
|
||||
uint8_t *gsd = g_game_save_data ? *g_game_save_data : NULL;
|
||||
|
||||
if (gsd == NULL || fn_hud_notify_script == NULL || unit_name == NULL)
|
||||
return;
|
||||
memset(blk, 0, sizeof(blk));
|
||||
fn_blk_ctor(blk);
|
||||
fn_blk_set_str(blk, "unit", unit_name);
|
||||
fn_blk_set_str(blk, "unit", bare_unit_name(unit_name));
|
||||
fn_blk_set_str(blk, "backup", backup);
|
||||
blk_set_int(blk, "slot", slot_id);
|
||||
fn_hud_notify_script(gsd + LMP_GSD_OFF_HUD_QUEUE, "wtoLocalMpBackupSpawn", blk);
|
||||
|
||||
@@ -0,0 +1,108 @@
|
||||
/* 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]));
|
||||
}
|
||||
@@ -139,12 +139,15 @@ static const LocalMpModule MODULES[] = {
|
||||
{ "local_mp_scores", install_local_mp_score_reader },
|
||||
{ "local_mp_kills", install_local_mp_kill_hooks },
|
||||
{ "local_mp_events", install_local_mp_event_hooks },
|
||||
{ "local_mp_captures", install_local_mp_capture_hooks },
|
||||
{ "local_mp_zones", install_local_mp_zone_hooks },
|
||||
{ "local_mp_nuke", install_local_mp_nuke_hooks },
|
||||
{ "local_mp_support", install_local_mp_support_hooks },
|
||||
{ "local_mp_damage_notifications", install_local_mp_damage_notification_hooks },
|
||||
{ "local_mp_hit_feedback", install_local_mp_hit_feedback_hooks },
|
||||
{ "local_mp_air_events", install_local_mp_air_event_hooks },
|
||||
{ "local_mp_ground_ai", install_local_mp_ground_ai_hooks },
|
||||
{ "local_mp_air_ai_sync", install_local_mp_air_ai_sync_hooks },
|
||||
};
|
||||
|
||||
static void use_core_values(void)
|
||||
|
||||
@@ -56,6 +56,7 @@ static int suppressed_avionics_logged;
|
||||
static int suppressed_optic_logged;
|
||||
static int suppressed_parts_logged;
|
||||
static int suppressed_enemy_mpi_logged;
|
||||
static int damage_hooks_queued;
|
||||
|
||||
static const uint8_t *local_mplayer(void)
|
||||
{
|
||||
@@ -99,17 +100,29 @@ static const uint8_t *watched_unit(const uint8_t *mplayer)
|
||||
}
|
||||
|
||||
/* The owner check also covers projectiles fired before switching to a support vehicle. */
|
||||
static int is_local_enemy_hit(const uint8_t *attacker, const uint8_t *victim)
|
||||
int local_mp_is_view_hit(const uint8_t *attacker, const uint8_t *victim)
|
||||
{
|
||||
const uint8_t *mplayer = local_mplayer();
|
||||
if (attacker == NULL || attacker == victim || mplayer == NULL)
|
||||
return 0;
|
||||
if (victim[LMP_UNIT_OFF_ARMY] != 0 && victim[LMP_UNIT_OFF_ARMY] == attacker[LMP_UNIT_OFF_ARMY])
|
||||
|
||||
const uint8_t *owner = owning_mplayer(attacker);
|
||||
if (owner != NULL && owner == owning_mplayer(victim))
|
||||
return 0;
|
||||
return owning_mplayer(attacker) == mplayer || attacker == controlled_unit(mplayer)
|
||||
return owner == mplayer || attacker == controlled_unit(mplayer)
|
||||
|| attacker == watched_unit(mplayer);
|
||||
}
|
||||
|
||||
int local_mp_has_enemy_hit_feedback(void)
|
||||
{
|
||||
return active_hit_victim != NULL;
|
||||
}
|
||||
|
||||
int local_mp_damage_notifications_ready(void)
|
||||
{
|
||||
return damage_hooks_queued;
|
||||
}
|
||||
|
||||
static uint8_t __fastcall hook_barrel_damage(void *damage, const uint8_t *impact)
|
||||
{
|
||||
/* The stock handler resolves the reference before it emits the notice and tags it in bit 0. */
|
||||
@@ -202,7 +215,9 @@ static uint64_t __fastcall hook_unit_on_event(void *unit, const uint8_t *event,
|
||||
if (unit != NULL && event != NULL && local_mp_is_host()
|
||||
&& *(const uint16_t *)(event + g_lmp.mpi_msg_id_off) == LMP_MPI_MSG_HIT_FEEDBACK) {
|
||||
const uint8_t *attacker = *(const uint8_t *const *)(event + g_lmp.hit_event_offender);
|
||||
if (is_local_enemy_hit(attacker, unit))
|
||||
const uint8_t *victim = unit;
|
||||
if (local_mp_is_view_hit(attacker, victim) &&
|
||||
(victim[LMP_UNIT_OFF_ARMY] == 0 || victim[LMP_UNIT_OFF_ARMY] != attacker[LMP_UNIT_OFF_ARMY]))
|
||||
active_hit_victim = unit;
|
||||
}
|
||||
result = original_unit_on_event(unit, event, arg3, arg4);
|
||||
@@ -288,5 +303,6 @@ int install_local_mp_damage_notification_hooks(void)
|
||||
log_line("local_mp: local_mp_damage_notifications skipped: barrel and breech deliver addresses differ");
|
||||
return 0;
|
||||
}
|
||||
return local_mp_queue_hooks("local_mp_damage_notifications", hooks, sizeof(hooks) / sizeof(hooks[0]));
|
||||
damage_hooks_queued = local_mp_queue_hooks("local_mp_damage_notifications", hooks, sizeof(hooks) / sizeof(hooks[0]));
|
||||
return damage_hooks_queued;
|
||||
}
|
||||
@@ -1,6 +1,6 @@
|
||||
/*
|
||||
* LocalMP non-fatal combat event dispatchers: deduplicated assists across air/ground/naval,
|
||||
* zone captures, hit results, severe damage, and naval damage awards.
|
||||
* hit results, severe damage, and naval damage awards.
|
||||
*
|
||||
* `IGroundModel::onBecameDead` calls both `IGroundModel::awardAssists` (`0x465540`) and
|
||||
* `Unit::awardAssists` (`0xe5b200` -> `dispatchAssist` `0x35beb0`); deduplicating `(victim, mp)`
|
||||
@@ -27,7 +27,6 @@ typedef struct 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 *DispatchHitFn)(
|
||||
int64_t uid, uint8_t *victim, uint8_t *offender, float dmg, uint8_t repeat_flush, uint8_t effective_hit, uint8_t extra);
|
||||
typedef void (__fastcall *DispatchSevereDamageFn)(int64_t uid, uint8_t *victim, uint8_t *offender);
|
||||
@@ -35,7 +34,6 @@ typedef void (__fastcall *DispatchNavalDamageFn)(int64_t uid, uint8_t *victim, u
|
||||
|
||||
static IGroundAwardAssistsFn orig_iground_award_assists;
|
||||
static DispatchAssistFn orig_dispatch_assist;
|
||||
static DispatchCaptureZoneFn orig_dispatch_capture_zone;
|
||||
static DispatchHitFn orig_dispatch_hit;
|
||||
static DispatchSevereDamageFn orig_dispatch_severe_damage;
|
||||
static DispatchNavalDamageFn orig_dispatch_naval_damage;
|
||||
@@ -135,27 +133,6 @@ static void __fastcall hook_dispatch_assist(int64_t uid, uint8_t *victim, uint8_
|
||||
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) {
|
||||
const uint8_t *own_unit = capturer_unit != NULL ? capturer_unit
|
||||
: (g_lmp_get_unit_by_eid ? (const uint8_t *)g_lmp_get_unit_by_eid(*(uint32_t *)(mp + LMP_MP_OFF_UNIT_EID)) : NULL);
|
||||
local_mp_inc_mplayer_stat(mp, LMP_MP_OFF_CAPTURE_ZONE);
|
||||
local_mp_add_mplayer_score(mp, local_mp_event_score("capture", own_unit, 1), LMP_EXP_EVENT_CAPTURE_ZONE);
|
||||
local_mp_mark_mplayer_dirty(mp);
|
||||
if (local_mp_is_local_mplayer(mp)) {
|
||||
LocalMpAwardEvent award = { LMP_EXP_EVENT_CAPTURE_ZONE, NULL, 0, 0, NULL, 0 };
|
||||
local_mp_report_award_event(&award);
|
||||
}
|
||||
}
|
||||
}
|
||||
orig_dispatch_capture_zone(uid, capturer_unit);
|
||||
}
|
||||
|
||||
/*
|
||||
* Unit::flushOffenderHitAward passes a repeat marker and an effective-hit flag. Its stock
|
||||
* single-player path (.58 0xffd369) selects HIT / INEFFECTIVE_HIT from that same flag. The
|
||||
@@ -240,7 +217,6 @@ int install_local_mp_event_hooks(void)
|
||||
const LocalMpHookSpec hooks[] = {
|
||||
{ "iground_award_assists", g_lmp.iground_award_assists, (void *)&hook_iground_award_assists, (void **)&orig_iground_award_assists },
|
||||
{ "dispatch_assist", g_lmp.dispatch_assist, (void *)&hook_dispatch_assist, (void **)&orig_dispatch_assist },
|
||||
{ "dispatch_capture_zone", g_lmp.dispatch_capture_zone, (void *)&hook_dispatch_capture_zone, (void **)&orig_dispatch_capture_zone },
|
||||
{ "dispatch_hit", g_lmp.dispatch_hit, (void *)&hook_dispatch_hit, (void **)&orig_dispatch_hit },
|
||||
{ "dispatch_severe_damage", g_lmp.dispatch_severe_damage, (void *)&hook_dispatch_severe_damage, (void **)&orig_dispatch_severe_damage },
|
||||
{ "dispatch_naval_damage", g_lmp.dispatch_naval_damage, (void *)&hook_dispatch_naval_damage, (void **)&orig_dispatch_naval_damage },
|
||||
|
||||
@@ -0,0 +1,63 @@
|
||||
/* Validate recipient ownership at the two outgoing hit-feedback dispatch points. */
|
||||
#include "local_mp_internal.h"
|
||||
#include "local_mp_offsets.h"
|
||||
|
||||
#include <intrin.h>
|
||||
|
||||
typedef void (__fastcall *SendScriptNetEventFn)(void *manager, uint8_t broadcast, uint32_t destination,
|
||||
const void *event, const char *event_name, const void *recipient_args, const void *recipient_filter);
|
||||
typedef void (__fastcall *NotifyHudScriptFn)(void *hud, int32_t event_id, const void *data);
|
||||
|
||||
/* The CmdShowHitMark unicast constructor writes 0x0001001c6c52bfea followed by its victim EID.
|
||||
* The stock sender handles event destruction when its flags require it. This event is plain data. */
|
||||
typedef struct HitMarkEvent {
|
||||
uint32_t type;
|
||||
uint16_t size;
|
||||
uint16_t flags;
|
||||
uint32_t victim;
|
||||
} HitMarkEvent;
|
||||
|
||||
enum { HIT_MARK_EVENT_TYPE = 0x6c52bfea, HIT_MARK_EVENT_SIZE = 0x1c, ECS_EVENT_UNICAST = 1 };
|
||||
enum { HUD_HINT_CHANGE_SHELL_TYPE = 0xc5 };
|
||||
|
||||
static SendScriptNetEventFn original_send_script_event;
|
||||
static NotifyHudScriptFn original_notify_hud_script;
|
||||
|
||||
static int should_drop_hit_mark(uint8_t broadcast, uint32_t destination, const HitMarkEvent *event)
|
||||
{
|
||||
if (event == NULL || event->type != HIT_MARK_EVENT_TYPE || event->size != HIT_MARK_EVENT_SIZE ||
|
||||
event->flags != ECS_EVENT_UNICAST || broadcast || !local_mp_is_host())
|
||||
return 0;
|
||||
|
||||
const uint8_t *attacker = g_lmp_get_unit_by_eid(destination);
|
||||
const uint8_t *victim = g_lmp_get_unit_by_eid(event->victim);
|
||||
return !local_mp_is_view_hit(attacker, victim);
|
||||
}
|
||||
|
||||
static void __fastcall hook_send_script_event(void *manager, uint8_t broadcast, uint32_t destination,
|
||||
const void *event, const char *event_name, const void *recipient_args, const void *recipient_filter)
|
||||
{
|
||||
if (!should_drop_hit_mark(broadcast, destination, event))
|
||||
original_send_script_event(manager, broadcast, destination, event, event_name, recipient_args, recipient_filter);
|
||||
}
|
||||
|
||||
static void __fastcall hook_notify_hud_script(void *hud, int32_t event_id, const void *data)
|
||||
{
|
||||
if (event_id == HUD_HINT_CHANGE_SHELL_TYPE &&
|
||||
(uintptr_t)_ReturnAddress() == (uintptr_t)g_lmp.hit_shell_hint_call + LMP_REL32_CALL_SIZE &&
|
||||
local_mp_is_host() && !local_mp_has_enemy_hit_feedback())
|
||||
return;
|
||||
original_notify_hud_script(hud, event_id, data);
|
||||
}
|
||||
|
||||
int install_local_mp_hit_feedback_hooks(void)
|
||||
{
|
||||
if (!local_mp_damage_notifications_ready())
|
||||
return 0;
|
||||
|
||||
const LocalMpHookSpec hooks[] = {
|
||||
{ "send_script_net_event", g_lmp.hit_mark_send, (void *)&hook_send_script_event, (void **)&original_send_script_event },
|
||||
{ "notify_shell_hint", g_lmp.hit_shell_hint_notify, (void *)&hook_notify_hud_script, (void **)&original_notify_hud_script },
|
||||
};
|
||||
return local_mp_queue_hooks("local_mp_hit_feedback", hooks, sizeof(hooks) / sizeof(hooks[0]));
|
||||
}
|
||||
@@ -62,6 +62,7 @@ void local_mp_players_queue_spawn(int32_t slot_id, int32_t spare_type, int32_t b
|
||||
|
||||
/* Local player events sent to the GUI scripts (local_mp_awards.c). */
|
||||
void local_mp_report_award_event(const LocalMpAwardEvent *ev);
|
||||
void local_mp_report_capture(const char *unit_name);
|
||||
void local_mp_report_nuclear_strike(void);
|
||||
void local_mp_report_airfield_spawn(const char *unit_name, int32_t base_id);
|
||||
void local_mp_report_backup_spawn(const char *unit_name, int32_t slot_id, const char *backup);
|
||||
@@ -103,15 +104,21 @@ int install_local_mp_action_hooks(void);
|
||||
int install_local_mp_award_hooks(void);
|
||||
int install_local_mp_kill_hooks(void);
|
||||
int install_local_mp_event_hooks(void);
|
||||
int install_local_mp_capture_hooks(void);
|
||||
int install_local_mp_score_reader(void);
|
||||
int install_local_mp_nuke_hooks(void);
|
||||
int install_local_mp_support_hooks(void);
|
||||
int install_local_mp_damage_notification_hooks(void);
|
||||
int install_local_mp_hit_feedback_hooks(void);
|
||||
int local_mp_damage_notifications_ready(void);
|
||||
int local_mp_is_view_hit(const uint8_t *attacker, const uint8_t *victim);
|
||||
int local_mp_has_enemy_hit_feedback(void);
|
||||
int install_local_mp_zone_hooks(void);
|
||||
void local_mp_zones_reset(void);
|
||||
int install_local_mp_air_event_hooks(void);
|
||||
int install_local_mp_ground_ai_hooks(void);
|
||||
void local_mp_ground_ai_update(float dt);
|
||||
int install_local_mp_air_ai_sync_hooks(void);
|
||||
|
||||
/* "wtoNav" requests of the ground AI script and the battle's navigation pack (local_mp_nav.c). */
|
||||
void local_mp_nav_request(void *blk);
|
||||
|
||||
@@ -147,9 +147,12 @@ static void process_unit_death(uint8_t *victim, uint8_t *killer_mp, int32_t kill
|
||||
}
|
||||
}
|
||||
|
||||
/* Stack buffer for Unit::chooseOffender; stock writes 0x124 bytes on 2.61.0.37/.58/.60. */
|
||||
#define LMP_OFFENDER_BUF_SIZE 0x180u
|
||||
|
||||
static uint8_t *resolve_offender_killer(uint8_t *victim, int32_t *out_army)
|
||||
{
|
||||
__declspec(align(16)) uint8_t offender[0x180];
|
||||
__declspec(align(16)) uint8_t offender[LMP_OFFENDER_BUF_SIZE];
|
||||
uintptr_t vtbl = victim ? *(uintptr_t *)victim : 0;
|
||||
ChooseOffenderVfn choose_fn;
|
||||
|
||||
@@ -209,6 +212,11 @@ int install_local_mp_kill_hooks(void)
|
||||
{ "on_unit_dead_once", g_lmp.on_unit_dead_once, (void *)&hook_on_unit_dead_once, (void **)&orig_on_unit_dead_once },
|
||||
};
|
||||
|
||||
if (LMP_OFFENDER_STRIDE > LMP_OFFENDER_BUF_SIZE) {
|
||||
log_line("local_mp: Offender stride 0x%zx exceeds the 0x%x-byte stack buffer",
|
||||
LMP_OFFENDER_STRIDE, LMP_OFFENDER_BUF_SIZE);
|
||||
return 0;
|
||||
}
|
||||
fn_mplayer_add_score = (MPlayerAddScoreFn)g_lmp.mplayer_add_score;
|
||||
fn_net_mark_dirty = (NetMarkDirtyFn)g_lmp.net_mark_dirty;
|
||||
|
||||
|
||||
@@ -15,6 +15,8 @@
|
||||
|
||||
#include "local_mp_values.h"
|
||||
|
||||
#define LMP_REL32_CALL_SIZE (1 + sizeof(int32_t)) /* x64 E8 + signed displacement */
|
||||
|
||||
#define LMP_GUI_STATE_PILOT_CONTROL 2
|
||||
#define LMP_GUI_STATE_CA_SELECT 6
|
||||
#define LMP_GUI_STATE_CA_READY 8
|
||||
|
||||
@@ -244,7 +244,8 @@ static uint8_t __fastcall hook_is_slot_ready_at_host(int32_t slot_id, const char
|
||||
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;
|
||||
/* Allow broken slots whose backup has not been used yet; isCrewAvailableInSession enforces backup eligibility. */
|
||||
return (*(uint32_t *)(mplayer + LMP_MP_OFF_USED_SPARES_MASK) & (1u << (uint32_t)slot_id)) == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
int install_local_mp_player_hooks(void)
|
||||
|
||||
@@ -37,12 +37,15 @@ typedef struct LmpValueSpec {
|
||||
#define SCORES "local_mp_scores"
|
||||
#define KILLS "local_mp_kills"
|
||||
#define EVENTS "local_mp_events"
|
||||
#define CAPTURES "local_mp_captures"
|
||||
#define ZONES "local_mp_zones"
|
||||
#define NUKE "local_mp_nuke"
|
||||
#define SUPPORT "local_mp_support"
|
||||
#define DAMAGE_NOTICES "local_mp_damage_notifications"
|
||||
#define HIT_FEEDBACK "local_mp_hit_feedback"
|
||||
#define AIR_EVENTS "local_mp_air_events"
|
||||
#define GROUND_AI "local_mp_ground_ai"
|
||||
#define AIR_AI_SYNC "local_mp_air_ai_sync"
|
||||
|
||||
static const LmpValueSpec SPECS[] = {
|
||||
A(ZONES, "apply_zone_damage", apply_zone_damage),
|
||||
@@ -137,10 +140,16 @@ static const LmpValueSpec SPECS[] = {
|
||||
O(KILLS, "stat_award_damage.field", mp_award_damage), O(KILLS, "stat_air_severe.field", mp_air_severe_dmg),
|
||||
O(KILLS, "stat_ship_severe.field", mp_ship_severe_dmg),
|
||||
|
||||
A(EVENTS, "dispatch_assist", dispatch_assist), A(EVENTS, "caller_capture_zone.call", dispatch_capture_zone),
|
||||
A(EVENTS, "dispatch_assist", dispatch_assist),
|
||||
A(EVENTS, "caller_hit_crit.call", dispatch_hit), A(EVENTS, "caller_severe_damage.call", dispatch_severe_damage),
|
||||
A(EVENTS, "caller_naval_damage.call", dispatch_naval_damage), O(EVENTS, "offender_assist.assist_sent", offender_assist_sent),
|
||||
|
||||
A(CAPTURES, "capture_cta_logic", capture_cta_logic),
|
||||
A(CAPTURES, "capture_set_owner", capture_set_owner), O(CAPTURES, "capture_set_owner.owner", capture_owner),
|
||||
A(CAPTURES, "capture_complete_call", capture_complete_call),
|
||||
A(CAPTURES, "capture_complete_call.set_owner", capture_complete_set_owner),
|
||||
A(CAPTURES, "capture_team_power", capture_team_power), A(CAPTURES, "capture_unit_power_call.function", capture_unit_power),
|
||||
|
||||
A(NUKE, "shell_launch", shell_launch), A(NUKE, "shell_explode", shell_explode), A(NUKE, "cta_logic_action", cta_logic_action),
|
||||
O(NUKE, "shell_instant_win.record", shell_launch_record), O(NUKE, "shell_instant_win.instant_win", shell_rec_instant_win),
|
||||
O(NUKE, "mission_vars_data.data", mission_vars_data), O(NUKE, "mission_vars_walk.count", mission_vars_count),
|
||||
@@ -171,6 +180,10 @@ static const LmpValueSpec SPECS[] = {
|
||||
O(DAMAGE_NOTICES, "enemy_part_damage_mpi.msg_id", enemy_part_dmg_mpi_id),
|
||||
O(DAMAGE_NOTICES, "enemy_part_hit_mpi.msg_id", enemy_part_hit_mpi_id),
|
||||
|
||||
A(HIT_FEEDBACK, "hit_mark_send.send", hit_mark_send),
|
||||
A(HIT_FEEDBACK, "hit_shell_hint_call", hit_shell_hint_call),
|
||||
A(HIT_FEEDBACK, "hit_shell_hint_call.notify", hit_shell_hint_notify),
|
||||
|
||||
O(AIR_EVENTS, "mission_mode_name.mode_name", mis_mode_name),
|
||||
A(AIR_EVENTS, "prepare_local_mission", prepare_local_mission),
|
||||
A(AIR_EVENTS, "prepare_local_mission_clear.use_kill_streaks", use_kill_streaks),
|
||||
@@ -200,6 +213,8 @@ static const LmpValueSpec SPECS[] = {
|
||||
A(GROUND_AI, "ground_ai_drive_to_pos_update", ground_ai_drive_to_pos_update),
|
||||
O(GROUND_AI, "ground_ai_move_properties.move_system", ground_ai_move_system),
|
||||
O(GROUND_AI, "ground_ai_move_annotation.inactive", ground_ai_move_inactive),
|
||||
|
||||
A(AIR_AI_SYNC, "air_ai_add_unsorted_plane", air_ai_add_unsorted_plane),
|
||||
};
|
||||
|
||||
static void store(const LmpValueSpec *spec, int64_t value, uint8_t *base)
|
||||
|
||||
@@ -61,9 +61,14 @@ typedef struct LmpValues {
|
||||
size_t mp_award_damage, mp_air_severe_dmg, mp_ship_severe_dmg;
|
||||
|
||||
/* local_mp_events */
|
||||
uint8_t *dispatch_assist, *dispatch_capture_zone, *dispatch_hit, *dispatch_severe_damage, *dispatch_naval_damage;
|
||||
uint8_t *dispatch_assist, *dispatch_hit, *dispatch_severe_damage, *dispatch_naval_damage;
|
||||
size_t offender_assist_sent;
|
||||
|
||||
/* local_mp_captures */
|
||||
uint8_t *capture_cta_logic, *capture_set_owner, *capture_complete_call, *capture_complete_set_owner;
|
||||
uint8_t *capture_team_power, *capture_unit_power;
|
||||
size_t capture_owner;
|
||||
|
||||
/* local_mp_nuke */
|
||||
uint8_t *shell_launch, *shell_explode, *cta_logic_action;
|
||||
size_t shell_launch_record, shell_rec_instant_win, mission_vars_data, mission_vars_count, mission_var_stride;
|
||||
@@ -82,6 +87,9 @@ typedef struct LmpValues {
|
||||
size_t barrel_unit_ref, breech_unit, barrel_notice_id, breech_notice_id, avionics_unit, hit_event_offender;
|
||||
size_t mpi_msg_id_off, enemy_part_dmg_mpi_id, enemy_part_hit_mpi_id;
|
||||
|
||||
/* local_mp_hit_feedback */
|
||||
uint8_t *hit_mark_send, *hit_shell_hint_call, *hit_shell_hint_notify;
|
||||
|
||||
/* local_mp_zones */
|
||||
uint8_t *apply_zone_damage;
|
||||
size_t zone_health, zone_max_health, zone_team, zone_flags, zone_airfield_mask;
|
||||
@@ -95,6 +103,8 @@ typedef struct LmpValues {
|
||||
/* local_mp_ground_ai */
|
||||
uint8_t *ground_ai_mission_action, *ground_ai_as_ground_model, *ground_ai_drive_to_pos_update;
|
||||
size_t ground_ai_move_system, ground_ai_move_inactive;
|
||||
/* local_mp_air_ai_sync */
|
||||
uint8_t *air_ai_add_unsorted_plane;
|
||||
} LmpValues;
|
||||
|
||||
extern LmpValues g_lmp;
|
||||
|
||||
Reference in new issue
Block a user