From 85532cd93021036b9e2f70663822ef632695bd42 Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Fri, 4 Dec 2026 01:06:04 +0800 Subject: [PATCH] feat(ground-ai)!: disable stock tankBot globally when AI script loads Replace per-bot mid-battle movement handback to stock AI with a clean binary startup gate: - Locate Unit::setBehaviorTree (ground_ai_set_beh_tree: .37 0x4e89b0, .58 0x4e8f60) in patches/native/local_mp_ground_ai.jsonc and hook it in native/wto-net/src/local_mp_ground_ai.c. - Announce readiness from [init] in wto_ai_runtime.das via wtoGroundAiScriptReady once the ground AI scripts finish compiling cleanly with custom movement enabled. When announced, hook_set_beh_tree suppresses attaching "tankBot" to LocalMP bot tanks and keeps their MoveSystem.inactive pinned to 1 for the life of the vehicle, ending all tug-of-war (external_inactive_reset) with stock AI. - If scripts fail to compile, are missing, or mode is "stock" / "fire", ownMovement stays 0 and stock tankBot runs untouched. - Remove per-bot handback, timeout release, and the now-obsolete navigation.returnToStockOnFailure config plumbing; on genuine script failure a bot halts in place and logs DRIVE_FAIL instead of silently switching to stock. Also initialize newly spawned bot ticks to run on frame 0 to eliminate spawn-frame invalid_drive_cmd noise. Verified MSVC build of wto_ws.dll (0 warnings in project C sources), root and launcher type checks, native module resolution on both 2.61.0.37 and 2.61.0.58 (0 failures), isolated 2.61.0.58 startup confirming 12/12 LocalMP modules installed, wto_ai_runtime.das loaded in 213 ms (0 compile errors), and "ground AI script ready (ownMovement=1; stock tankBot disabled)" in wto_ws.log. BREAKING CHANGE: removes navigation.returnToStockOnFailure from tuning/ground-ai.jsonc; stock tankBot is now controlled strictly by whether the custom ground AI script loaded with custom movement enabled. --- apps/server/src/tuning/ground-ai-tuning.ts | 1 - apps/server/tuning/ground-ai.jsonc | 3 - game-ai/ground/wto_ai_drive_common.das | 65 ++++------- game-ai/ground/wto_ai_runtime.das | 14 ++- native/wto-net/src/hook_config.c | 10 -- native/wto-net/src/hook_config.h | 2 - native/wto-net/src/local_mp_ground_ai.c | 105 ++++++++++-------- native/wto-net/src/local_mp_values.c | 1 + native/wto-net/src/local_mp_values.h | 2 +- packages/patcher/src/build-game-copy.ts | 3 - .../patcher/src/ground-ai/ground-ai-config.ts | 2 - packages/patcher/src/network/network-hook.ts | 6 +- patches/native/local_mp_ground_ai.jsonc | 15 ++- 13 files changed, 105 insertions(+), 124 deletions(-) diff --git a/apps/server/src/tuning/ground-ai-tuning.ts b/apps/server/src/tuning/ground-ai-tuning.ts index 2b464bf..1d65238 100644 --- a/apps/server/src/tuning/ground-ai-tuning.ts +++ b/apps/server/src/tuning/ground-ai-tuning.ts @@ -184,7 +184,6 @@ function readNavigationSection(nav: TuningReader): GroundAiTuning['navigation'] steerSign, deadEchoSec: nav.number('deadEchoSec', { min: 0.3, max: 10 }), controlTimeoutSec: nav.number('controlTimeoutSec', { min: 0.3, max: 10 }), - returnToStockOnFailure: nav.bool('returnToStockOnFailure'), cornerBrakeAccel: nav.number('cornerBrakeAccel', { min: 0.5, max: 8 }), pivotAngleDeg: nav.number('pivotAngleDeg', { min: 25, max: 150 }), stuckWindowSec: nav.number('stuckWindowSec', { min: 1, max: 15 }), diff --git a/apps/server/tuning/ground-ai.jsonc b/apps/server/tuning/ground-ai.jsonc index a524ca9..94be90a 100644 --- a/apps/server/tuning/ground-ai.jsonc +++ b/apps/server/tuning/ground-ai.jsonc @@ -101,9 +101,6 @@ "steerSign": 1.0, "deadEchoSec": 1.2, "controlTimeoutSec": 1.0, - // When false, failed or timed-out bots brake in place and log the cause instead of - // handing movement back to stock tankBot (intended for testing). - "returnToStockOnFailure": true, "cornerBrakeAccel": 1.75, "pivotAngleDeg": 75.0, "stuckWindowSec": 3.6, diff --git a/game-ai/ground/wto_ai_drive_common.das b/game-ai/ground/wto_ai_drive_common.das index 297ad1d..a45386e 100644 --- a/game-ai/ground/wto_ai_drive_common.das +++ b/game-ai/ground/wto_ai_drive_common.das @@ -18,6 +18,13 @@ require %appGame.wtoai.wto_ai_config_common require %appGame.wtoai.wto_ai_math_common require %appGame.wtoai.wto_ai_types_common +[never_inline] +def public wto_drive_announce_script_ready() + let own = (WTO_AI_ENABLED && WTO_AI_LAYER_NAVIGATION && WTO_AI_NAV_DRIVE_MODE == "vehicle_phys") ? "1" : "0" + using() <| $(var blk : DataBlock) + add(blk, "ownMovement", own) + call_mission_action("wtoGroundAiScriptReady", blk) + [never_inline] def public wto_drive_request_control(eid : EntityId; holdMs : int) using() <| $(var blk : DataBlock) @@ -56,7 +63,8 @@ def private wto_check_echo_watchdog(unitMissionName : string; var actor : Vehicl if !throttleEchoed || !steeringEchoed st.deadEchoSec += clamp(dt, 0.0, 0.15) if st.deadEchoSec >= WTO_AI_NAV_DEAD_ECHO_SEC - print("WTO_AI|PHYS_FALLBACK|actor={unitMissionName}|eid={uint(slot.eid)}|autoReturn={WTO_AI_NAV_RETURN_TO_STOCK}\n") + if !st.failLogged + print("WTO_AI|PHYS_STALL|actor={unitMissionName}|eid={uint(slot.eid)}\n") return false else st.deadEchoSec = 0.0 @@ -134,21 +142,6 @@ def private wto_compute_cruise_axes(cmd : WtoDriveCmd const&; spec : WtoVehicleS else outThr = clamp(0.45 + vErr * 0.45, 0.15, 1.0) -[never_inline] -def private wto_release_phys_owner(gm : IGroundModel const?; var actor : VehiclePhysActor&; - var slot : WtoBotSlot&; reason : string) - assume st = slot.drive - if !st.routeBOwned - return - print("WTO_AI|DRIVE_RELEASE|eid={uint(slot.eid)}|reason={reason}\n") - if gm != null && gm.moveSys != null && gm.moveSys.inactive - wto_set_phys_axes(actor, 0.0, 0.0, 0.0, 0.0) - wto_drive_request_control(slot.eid, 0) - st.routeBOwned = false - st.prevThr = 0.0 - st.prevStr = 0.0 - st.deadEchoSec = 0.0 - [never_inline] def private wto_drive_is_immobilized(actor : VehiclePhysActor const&) : bool assume dmg = actor.phys.currentState.damageState @@ -156,41 +149,27 @@ def private wto_drive_is_immobilized(actor : VehiclePhysActor const&) : bool dmg.driverReadyness <= 0.0 || (dmg.trackLBroken && dmg.trackRBroken)) [never_inline] -def private wto_drive_handle_failure(gm : IGroundModel const?; var actor : VehiclePhysActor&; - var slot : WtoBotSlot&; reason : string; permanent : bool) +def private wto_drive_halt_on_failure(var actor : VehiclePhysActor&; + var slot : WtoBotSlot&; reason : string) assume st = slot.drive - if WTO_AI_NAV_RETURN_TO_STOCK - if permanent - st.routeAFallback = true - wto_release_phys_owner(gm, actor, slot, reason) - return if !st.failLogged st.failLogged = true - print("WTO_AI|DRIVE_FAIL|eid={uint(slot.eid)}|reason={reason}|autoReturn=false\n") + print("WTO_AI|DRIVE_FAIL|eid={uint(slot.eid)}|reason={reason}\n") st.prevThr = 0.0 st.prevStr = 0.0 st.deadEchoSec = 0.0 wto_set_phys_axes(actor, 0.0, 0.0, 1.0, 1.0) [never_inline] -def private wto_prepare_phys_owner(gm : IGroundModel const?; var actor : VehiclePhysActor&; - now : float; var slot : WtoBotSlot&) : bool +def private wto_ensure_phys_owner(gm : IGroundModel const?; var actor : VehiclePhysActor&; + var slot : WtoBotSlot&) : bool assume st = slot.drive if gm == null || gm.moveSys == null - wto_release_phys_owner(gm, actor, slot, "missing_movesys") return false - if st.routeBOwned && !gm.moveSys.inactive - wto_release_phys_owner(gm, actor, slot, "external_inactive_reset") - st.nextControlRequestAt = now + 1.0 - return false - if now >= st.nextControlRequestAt - if !st.routeBOwned && gm.moveSys.inactive - return false - wto_drive_request_control(slot.eid, int(WTO_AI_NAV_CONTROL_TIMEOUT_SEC * 1000.0)) + if !st.routeBOwned || !gm.moveSys.inactive + wto_drive_request_control(slot.eid, 1000) if !gm.moveSys.inactive - st.nextControlRequestAt = now + WTO_AI_NAV_CONTROL_TIMEOUT_SEC return false - st.nextControlRequestAt = now + min(WTO_AI_NAV_TICK_SEC, WTO_AI_NAV_CONTROL_TIMEOUT_SEC * 0.5) if !st.routeBOwned slot.spec.isTracked = actor.phys.trackWidth > 0.01 slot.spec.canPivot = slot.spec.isTracked && actor.phys.haveSeparateBrakes @@ -201,15 +180,15 @@ def private wto_prepare_phys_owner(gm : IGroundModel const?; var actor : Vehicle def public wto_drive_step_phys(var unit : Unit?; unitMissionName : string; gm : IGroundModel const?; var actor : VehiclePhysActor&; dt, now : float; var slot : WtoBotSlot&) - if unit == null || actor.physEdit == null || slot.drive.routeAFallback + if unit == null || actor.physEdit == null return - if !wto_prepare_phys_owner(gm, actor, now, slot) + if !wto_ensure_phys_owner(gm, actor, slot) return if !slot.driveCmd.valid || (!slot.order.valid && !WTO_AI_LAYER_TACTICS) - wto_drive_handle_failure(gm, actor, slot, "invalid_drive_cmd", false) + wto_drive_halt_on_failure(actor, slot, "invalid_drive_cmd") return - if now > slot.nextNavAt + WTO_AI_NAV_TICK_SEC - wto_drive_handle_failure(gm, actor, slot, "stale_nav_tick", false) + if now > slot.nextNavAt + WTO_AI_NAV_TICK_SEC * 2.0 + wto_drive_halt_on_failure(actor, slot, "stale_nav_tick") return let immobile = wto_drive_is_immobilized(actor) slot.tactics.immobilized = immobile @@ -220,7 +199,7 @@ def public wto_drive_step_phys(var unit : Unit?; unitMissionName : string; wto_set_phys_axes(actor, 0.0, 0.0, 1.0, 1.0) return if !wto_check_echo_watchdog(unitMissionName, actor, dt, slot) - wto_drive_handle_failure(gm, actor, slot, "dead_echo", true) + wto_drive_halt_on_failure(actor, slot, "dead_echo") return slot.drive.failLogged = false vehicle_actor_set_allow_move_control(actor, true) diff --git a/game-ai/ground/wto_ai_runtime.das b/game-ai/ground/wto_ai_runtime.das index 941fe4d..775e92b 100644 --- a/game-ai/ground/wto_ai_runtime.das +++ b/game-ai/ground/wto_ai_runtime.das @@ -51,6 +51,10 @@ var private g_next_diag_at : float = 0.0 def private wto_any_layer_active() : bool return WTO_AI_ENABLED && (WTO_AI_LAYER_MACRO || WTO_AI_LAYER_TACTICS || WTO_AI_LAYER_NAVIGATION || WTO_AI_LAYER_FIRE_CONTROL) +[init] +def wto_ai_script_init() + wto_drive_announce_script_ready() + [never_inline] def private wto_reset_runtime() wto_world_reset(g_world) @@ -93,9 +97,9 @@ def private wto_acquire_slot(eid : EntityId; army : int; now : float) : int g_bots[freeIdx].eid = eid g_bots[freeIdx].army = army g_bots[freeIdx].lastSeenAt = now - g_bots[freeIdx].nextTacticsAt = now + float(freeIdx % 8) * (WTO_AI_TACTICS_TICK_SEC / 8.0) - g_bots[freeIdx].nextNavAt = now + float(freeIdx % 10) * (WTO_AI_NAV_TICK_SEC / 10.0) - g_bots[freeIdx].route.nextReplanAt = now + float(freeIdx % 12) * 0.2 + g_bots[freeIdx].nextTacticsAt = now - 0.01 + g_bots[freeIdx].nextNavAt = now - 0.01 + g_bots[freeIdx].route.nextReplanAt = now - 0.01 g_cmd_dirty = true return freeIdx @@ -114,6 +118,7 @@ def private wto_phys_slot_available() : bool [es(tag=server, on_event=(EventMissionUnload, EventEntityManagerBeforeClear, EventEcsMissionLoaded))] def wto_ai_mission_reset_es(evt : Event) wto_reset_runtime() + wto_drive_announce_script_ready() [es(tag=server)] def wto_ai_zone_captured_es(evt : EventZoneCaptured) @@ -199,6 +204,7 @@ def wto_ai_world_tick_es(act : UpdateStageInfoAct) if g_bots[i].used && (now - g_bots[i].lastSeenAt) > 3.5 g_bots[i] = WtoBotSlot() if !g_world.valid + wto_drive_announce_script_ready() print("WTO_AI|RUNTIME_READY\n") wto_world_refresh(now, g_world) wto_crowd_update_all(g_world, g_bots, g_crowd) @@ -272,7 +278,7 @@ def wto_ai_phys_tick_es(act : UpdateStageInfoAct; eid : EntityId; var unit__ref if unit == null || !unit.isAlive || unit.isDelayed || unit.isHumanPlayer || vehicle_net_phys.physEdit == null return let idx = wto_find_slot(eid) - if idx < 0 || g_bots[idx].drive.routeAFallback + if idx < 0 return if !g_bots[idx].drive.routeBOwned && !wto_phys_slot_available() return diff --git a/native/wto-net/src/hook_config.c b/native/wto-net/src/hook_config.c index db97098..a049a16 100644 --- a/native/wto-net/src/hook_config.c +++ b/native/wto-net/src/hook_config.c @@ -5,8 +5,6 @@ * port= without a valid port the hooks still answer every host name * locally but refuse every connection that would leave the machine * log=0|1 optional, defaults to 1; when 0, wto_ws.log is not opened - * ground_ai_return_to_stock=0|1 optional, defaults to 1; when 0, timed-out ground AI control - * stays paused instead of returning to stock tankBot (testing) * exe.time_date_stamp=0x... the executable the native values were resolved for * exe.size_of_image=0x... * native.= what the LocalMP modules need from the executable: RVAs of @@ -37,7 +35,6 @@ static wchar_t g_folder[MAX_PATH]; static CRITICAL_SECTION g_log_lock; static FILE *g_log; static int g_log_enabled = 1; -static int g_ground_ai_return_to_stock = 1; static NativeValue g_native[NATIVE_VALUES_MAX]; static size_t g_native_count; static int64_t g_exe_time_date_stamp = -1; @@ -105,8 +102,6 @@ static void read_settings(void) read_port(line + 5); else if (strncmp(line, "log=", 4) == 0) g_log_enabled = atoi(line + 4) != 0; - else if (strncmp(line, "ground_ai_return_to_stock=", 26) == 0) - g_ground_ai_return_to_stock = atoi(line + 26) != 0; else if (strncmp(line, "exe.time_date_stamp=", 20) == 0) parse_value(line + 20, &g_exe_time_date_stamp); else if (strncmp(line, "exe.size_of_image=", 18) == 0) @@ -143,11 +138,6 @@ int config_native_matches_executable(void) (int64_t)nt->OptionalHeader.SizeOfImage == g_exe_size_of_image; } -int config_ground_ai_return_to_stock(void) -{ - return g_ground_ai_return_to_stock; -} - void config_load(HMODULE self) { wchar_t path[MAX_PATH]; diff --git a/native/wto-net/src/hook_config.h b/native/wto-net/src/hook_config.h index ec208d2..5e232f8 100644 --- a/native/wto-net/src/hook_config.h +++ b/native/wto-net/src/hook_config.h @@ -13,5 +13,3 @@ void describe_address(const struct sockaddr *name, int length, char *text, size_ int config_native_value(const char *name, int64_t *value); /* Whether the settings were resolved for the executable this process runs (PE time stamp and size). */ int config_native_matches_executable(void); -/* Whether timed-out ground AI control returns to stock tankBot (wto_ws.cfg "ground_ai_return_to_stock="); 1 by default. */ -int config_ground_ai_return_to_stock(void); diff --git a/native/wto-net/src/local_mp_ground_ai.c b/native/wto-net/src/local_mp_ground_ai.c index 64df48e..22ef76f 100644 --- a/native/wto-net/src/local_mp_ground_ai.c +++ b/native/wto-net/src/local_mp_ground_ai.c @@ -1,7 +1,13 @@ /* - * Temporarily pause stock tank movement for a LocalMP bot receiving custom physics inputs. - * Only the native side changes the MoveSystem flag, so it can give control back if the script - * stops renewing it. All other mission actions still go through the original daScript binding. + * Global stock-tankBot replacement gate for LocalMP battles. + * + * When WTOffline's ground AI daScript compiles and loads cleanly with custom movement enabled, + * its [init] hook announces "wtoGroundAiScriptReady". Once announced, stock "tankBot" behavior + * trees are never attached to LocalMP bot tanks and their MoveSystem stays paused for the + * lifetime of the vehicle (no mid-battle fallback or tug-of-war with stock AI). + * + * If the script fails to compile, is missing, or the player chooses "stock" mode, the ready + * signal never arrives and stock tankBot runs untouched. */ #include "hook_config.h" #include "local_mp_internal.h" @@ -11,29 +17,30 @@ #include #include +#define SCRIPT_READY_ACTION "wtoGroundAiScriptReady" #define DRIVE_CONTROL_ACTION "wtoGroundAiDriveControl" typedef void (__fastcall *MissionActionFn)(const char *name, const void *blk); typedef uint8_t *(__fastcall *AsGroundModelFn)(uint8_t *unit); +typedef void (__fastcall *SetBehTreeFn)(uint8_t *unit, const char *tree_name, uint8_t force); typedef struct GroundAiDriveControl { uint8_t *unit; uint8_t *move_system; uint32_t eid; - float remaining_seconds; - int stalled_logged; } GroundAiDriveControl; static MissionActionFn orig_mission_action; +static SetBehTreeFn orig_set_beh_tree; static AsGroundModelFn as_ground_model; -/* Player IDs are one byte in the engine. */ +static volatile LONG g_script_owns_movement; static GroundAiDriveControl controls[UINT8_MAX + 1]; static SRWLOCK control_lock = SRWLOCK_INIT; static uint8_t *get_move_system(uint8_t *unit) { - uint8_t *ground_model = as_ground_model(unit); + uint8_t *ground_model = unit ? as_ground_model(unit) : NULL; return ground_model ? *(uint8_t **)(ground_model + g_lmp.ground_ai_move_system) : NULL; } @@ -48,41 +55,31 @@ static uint8_t *get_bot_owner(uint8_t *unit, uint32_t eid) return owner; } -static void give_back_drive(GroundAiDriveControl *control, const char *reason) +static void clear_slot(GroundAiDriveControl *control, const char *reason) { - uint8_t *unit = (uint8_t *)g_lmp_get_unit_by_eid(control->eid); - - /* The old unit or its movement component may already have been destroyed. */ - if (unit == control->unit && get_move_system(unit) == control->move_system) - control->move_system[g_lmp.ground_ai_move_inactive] = 0; - log_line("local_mp: ground AI returned drive eid=%#lx (%s)", (unsigned long)control->eid, reason); + log_line("local_mp: ground AI cleared drive slot eid=%#lx (%s)", (unsigned long)control->eid, reason); memset(control, 0, sizeof(*control)); } -static void release_by_eid(uint32_t eid, const char *reason) +static void clear_by_eid(uint32_t eid, const char *reason) { size_t i; for (i = 0; i < sizeof(controls) / sizeof(controls[0]); i++) { if (controls[i].unit == NULL) continue; if (eid == 0 || controls[i].eid == eid) - give_back_drive(&controls[i], reason); + clear_slot(&controls[i], reason); } } -static void update_drive_control(uint32_t eid, uint32_t hold_ms) +static void acquire_drive_control(uint32_t eid) { uint8_t *unit; uint8_t *move_system; uint8_t *owner; GroundAiDriveControl *control; - uint8_t *inactive; - if (hold_ms == 0) { - release_by_eid(eid, eid == 0 ? "mission reset" : "script released"); - return; - } - if (eid == 0 || !local_mp_is_host()) + if (eid == 0 || !local_mp_is_host() || !InterlockedCompareExchange(&g_script_owns_movement, 0, 0)) return; unit = (uint8_t *)g_lmp_get_unit_by_eid(eid); move_system = get_move_system(unit); @@ -92,20 +89,15 @@ static void update_drive_control(uint32_t eid, uint32_t hold_ms) control = &controls[owner[LMP_MP_OFF_PID]]; if (control->unit != NULL && (control->eid != eid || control->unit != unit || control->move_system != move_system)) - give_back_drive(control, "vehicle changed"); + clear_slot(control, "vehicle changed"); - inactive = move_system + g_lmp.ground_ai_move_inactive; + move_system[g_lmp.ground_ai_move_inactive] = 1; if (control->unit == NULL) { - if (*inactive) - return; /* Leave mission-disabled vehicles under their existing owner. */ control->unit = unit; control->move_system = move_system; control->eid = eid; - *inactive = 1; - log_line("local_mp: ground AI acquired drive eid=%#lx", (unsigned long)eid); + log_line("local_mp: ground AI owns drive eid=%#lx", (unsigned long)eid); } - control->remaining_seconds = (float)hold_ms / 1000.0f; - control->stalled_logged = 0; } static int read_uint(const void *blk, const char *key, uint32_t *out) @@ -124,20 +116,44 @@ static int read_uint(const void *blk, const char *key, uint32_t *out) return 1; } +static void __fastcall hook_set_beh_tree(uint8_t *unit, const char *tree_name, uint8_t force) +{ + if (local_mp_is_host() && InterlockedCompareExchange(&g_script_owns_movement, 0, 0) && + tree_name != NULL && strcmp(tree_name, "tankBot") == 0 && unit != NULL) { + uint8_t *move_system = get_move_system(unit); + if (move_system != NULL) + move_system[g_lmp.ground_ai_move_inactive] = 1; + log_line("local_mp: suppressed stock tankBot for unit=%p (custom ground AI loaded)", (void *)unit); + return; + } + orig_set_beh_tree(unit, tree_name, force); +} + static void __fastcall hook_mission_action(const char *name, const void *blk) { - uint32_t eid, hold_ms; + uint32_t eid = 0, hold_ms = 0, own = 0; + if (name != NULL && strcmp(name, SCRIPT_READY_ACTION) == 0) { + if (blk != NULL && read_uint(blk, "ownMovement", &own)) { + LONG prev = InterlockedExchange(&g_script_owns_movement, own ? 1 : 0); + if (prev != (own ? 1 : 0)) { + log_line("local_mp: ground AI script ready (ownMovement=%u; stock tankBot %s)", + (unsigned)(own ? 1 : 0), own ? "disabled" : "kept"); + } + } + return; + } if (name == NULL || strcmp(name, DRIVE_CONTROL_ACTION) != 0) { orig_mission_action(name, blk); return; } if (blk == NULL || !read_uint(blk, "eid", &eid) || !read_uint(blk, "holdMs", &hold_ms)) return; - if (hold_ms > 0 && (eid == 0 || !local_mp_is_host())) - return; AcquireSRWLockExclusive(&control_lock); - update_drive_control(eid, hold_ms); + if (hold_ms == 0) + clear_by_eid(eid, eid == 0 ? "mission reset" : "unit ended"); + else + acquire_drive_control(eid); ReleaseSRWLockExclusive(&control_lock); } @@ -145,6 +161,7 @@ void local_mp_ground_ai_update(float dt) { size_t i; int hosting; + (void)dt; if (orig_mission_action == NULL) return; @@ -156,26 +173,17 @@ void local_mp_ground_ai_update(float dt) if (control->unit == NULL) continue; if (!hosting) { - give_back_drive(control, "session ended"); + clear_slot(control, "session ended"); continue; } unit = (uint8_t *)g_lmp_get_unit_by_eid(control->eid); owner = unit == control->unit ? get_bot_owner(unit, control->eid) : NULL; if (owner == NULL || owner[LMP_MP_OFF_PID] != i || get_move_system(unit) != control->move_system) { - give_back_drive(control, "vehicle changed"); + clear_slot(control, "vehicle changed"); continue; } - if (dt > 0.0f) - control->remaining_seconds -= dt; - if (control->remaining_seconds <= 0.0f) { - if (config_ground_ai_return_to_stock()) { - give_back_drive(control, "script stopped renewing control"); - } else if (!control->stalled_logged) { - control->stalled_logged = 1; - log_line("local_mp: ground AI control stalled eid=%#lx (auto-return disabled; stock movement kept paused)", - (unsigned long)control->eid); - } - } + /* Keep stock MoveSystem permanently paused while this bot tank is alive. */ + control->move_system[g_lmp.ground_ai_move_inactive] = 1; } ReleaseSRWLockExclusive(&control_lock); } @@ -184,6 +192,7 @@ int install_local_mp_ground_ai_hooks(void) { LocalMpHookSpec hooks[] = { { "das_call_mission_action", g_lmp.ground_ai_mission_action, (void *)&hook_mission_action, (void **)&orig_mission_action }, + { "unit_set_beh_tree", g_lmp.ground_ai_set_beh_tree, (void *)&hook_set_beh_tree, (void **)&orig_set_beh_tree }, }; as_ground_model = (AsGroundModelFn)g_lmp.ground_ai_as_ground_model; diff --git a/native/wto-net/src/local_mp_values.c b/native/wto-net/src/local_mp_values.c index 7dabc40..aea8fef 100644 --- a/native/wto-net/src/local_mp_values.c +++ b/native/wto-net/src/local_mp_values.c @@ -190,6 +190,7 @@ static const LmpValueSpec SPECS[] = { A(GROUND_AI, "ground_ai_mission_binding.action", ground_ai_mission_action), A(GROUND_AI, "ground_ai_as_ground_model", ground_ai_as_ground_model), + A(GROUND_AI, "ground_ai_set_beh_tree", ground_ai_set_beh_tree), 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), }; diff --git a/native/wto-net/src/local_mp_values.h b/native/wto-net/src/local_mp_values.h index e59a65e..a8d548b 100644 --- a/native/wto-net/src/local_mp_values.h +++ b/native/wto-net/src/local_mp_values.h @@ -88,7 +88,7 @@ typedef struct LmpValues { size_t mis_mode_name, gp_ks_rules, gp_ks_rule_count, ks_rule_tag, ks_rule_air_ai_mult, ks_rule_ground_ai_mult; size_t ks_rule_spawn_pos, ks_rule_spawn_pos_count, ks_spawn_pos_stride, mp_ks_progress, app_terrain; /* local_mp_ground_ai */ - uint8_t *ground_ai_mission_action, *ground_ai_as_ground_model; + uint8_t *ground_ai_mission_action, *ground_ai_as_ground_model, *ground_ai_set_beh_tree; size_t ground_ai_move_system, ground_ai_move_inactive; } LmpValues; diff --git a/packages/patcher/src/build-game-copy.ts b/packages/patcher/src/build-game-copy.ts index 5ede41d..2666592 100644 --- a/packages/patcher/src/build-game-copy.ts +++ b/packages/patcher/src/build-game-copy.ts @@ -140,9 +140,6 @@ export function buildGameCopy(inputs: GameCopyInputs): GameCopyBuild { const executableFolder = dirname(GAME_FILES.executable); const hookSettings = networkHookSettings(endpoint, stockImage, native.values, { loggingEnabled: inputs.hookLogging ?? true, - ...(customGroundDrive && inputs.groundAi?.config.navigation.returnToStockOnFailure === false - ? { groundAiReturnToStock: false } - : {}), }); const files: GameCopyFile[] = [ { path: GAME_FILES.charPack, content: core.charPack }, diff --git a/packages/patcher/src/ground-ai/ground-ai-config.ts b/packages/patcher/src/ground-ai/ground-ai-config.ts index 8f159f5..afdbdc4 100644 --- a/packages/patcher/src/ground-ai/ground-ai-config.ts +++ b/packages/patcher/src/ground-ai/ground-ai-config.ts @@ -88,7 +88,6 @@ export interface GroundAiConfig { readonly steerSign: number; readonly deadEchoSec: number; readonly controlTimeoutSec: number; - readonly returnToStockOnFailure: boolean; readonly cornerBrakeAccel: number; readonly pivotAngleDeg: number; readonly stuckWindowSec: number; @@ -269,7 +268,6 @@ function collectConfigEntries(c: GroundAiConfig): readonly DasEntry[] { ['WTO_AI_NAV_STEER_SIGN', 'float', c.navigation.steerSign], ['WTO_AI_NAV_DEAD_ECHO_SEC', 'float', c.navigation.deadEchoSec], ['WTO_AI_NAV_CONTROL_TIMEOUT_SEC', 'float', c.navigation.controlTimeoutSec], - ['WTO_AI_NAV_RETURN_TO_STOCK', 'bool', c.navigation.returnToStockOnFailure], ['WTO_AI_NAV_CORNER_BRAKE_ACCEL', 'float', c.navigation.cornerBrakeAccel], ['WTO_AI_NAV_PIVOT_ANGLE_DEG', 'float', c.navigation.pivotAngleDeg], ['WTO_AI_NAV_STUCK_WINDOW_SEC', 'float', c.navigation.stuckWindowSec], diff --git a/packages/patcher/src/network/network-hook.ts b/packages/patcher/src/network/network-hook.ts index cb2c3f7..583dbbf 100644 --- a/packages/patcher/src/network/network-hook.ts +++ b/packages/patcher/src/network/network-hook.ts @@ -17,15 +17,11 @@ export function networkHookSettings( endpoint: LocalEndpoint, stock: PeImage, nativeValues: ReadonlyMap, - options?: { - readonly loggingEnabled?: boolean; - readonly groundAiReturnToStock?: boolean; - }, + options?: { readonly loggingEnabled?: boolean }, ): { name: string; content: Uint8Array } { const lines = [ `port=${endpoint.port}`, ...(options?.loggingEnabled === false ? ['log=0'] : []), - ...(options?.groundAiReturnToStock === false ? ['ground_ai_return_to_stock=0'] : []), ...nativeSettingsLines(stock, nativeValues), ]; return { name: SETTINGS, content: new TextEncoder().encode(`${lines.join('\n')}\n`) }; diff --git a/patches/native/local_mp_ground_ai.jsonc b/patches/native/local_mp_ground_ai.jsonc index e7106d7..79c7588 100644 --- a/patches/native/local_mp_ground_ai.jsonc +++ b/patches/native/local_mp_ground_ai.jsonc @@ -56,12 +56,23 @@ "written_for": "2.61.0.37", "locate": { "method": "signature", - "pattern": "48 b8 69 6e 61 63 74 69 76 65 48 89 44 24 30 c6 44 24 38 00 c6 44 24 67 0f 48 89 44 24 50 c6 44 24 58 00 48 8b 8b a8 01 00 00 e8 ?? ?? ?? ?? 48 89 84 24 a0 00 00 00 4c 89 74 24 20 48 8d 54 24 50 4c 8d 44 24 30 48 89 d9 41 b9 ?? ?? ?? ?? e8 ?? ?? ?? ??", - "captures": { + "pattern": "48 b8 69 6e 61 63 74 69 76 65 48 89 44 24 30 c6 44 24 38 00 c6 44 24 67 0f 48 89 44 24 50 c6 44 24 58 00 48 8b 8b a8 01 00 00 e8 ?? ?? ?? ?? 48 89 84 24 a0 00 00 00 4c 89 74 24 20 48 8d 54 24 50 4c 8d 44 24 30 48 89 d9 41 b9 ?? ?? ?? ?? e8 ?? ?? ?? ??" + ,"captures": { "inactive": { "offset": 75, "type": "u32" } } } }] + }, + // Unit::setBehaviorTree (vtable +0x1f0 and direct calls from BotSystem attaching "tankBot"). + // 2.61.0.37: 0x4e89b0. 2.61.0.58: 0x4e8f60. + "ground_ai_set_beh_tree": { + "variants": [{ + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "pattern": "41 56 56 57 53 48 83 ec 48 8b 81 ?? ?? ?? ?? a9 00 01 00 00 75 1a 48 8b 81 ?? ?? ?? ?? 48 85 c0 74 2e f6 80 ?? ?? ?? ?? 80 75 25 e9 ?? ?? ?? ??" + } + }] } } }