diff --git a/native/wto-net/src/local_mp_ground_ai.c b/native/wto-net/src/local_mp_ground_ai.c index 22ef76f..9dbbcf7 100644 --- a/native/wto-net/src/local_mp_ground_ai.c +++ b/native/wto-net/src/local_mp_ground_ai.c @@ -22,7 +22,7 @@ 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 uint8_t (__fastcall *DriveToPosUpdateFn)(void *node, void *agent, float dt); typedef struct GroundAiDriveControl { uint8_t *unit; @@ -31,7 +31,7 @@ typedef struct GroundAiDriveControl { } GroundAiDriveControl; static MissionActionFn orig_mission_action; -static SetBehTreeFn orig_set_beh_tree; +static DriveToPosUpdateFn orig_drive_to_pos_update; static AsGroundModelFn as_ground_model; static volatile LONG g_script_owns_movement; @@ -116,17 +116,13 @@ 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) +static uint8_t __fastcall hook_drive_to_pos_update(void *node, void *agent, float dt) { - 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); + /* Keep the BehTree object initialized on the unit so vehicle physics steps normally, + * but short-circuit stock driveToPos to ER_SUCCESS (1) whenever our AI script is active. */ + if (local_mp_is_host() && InterlockedCompareExchange(&g_script_owns_movement, 0, 0)) + return 1; + return orig_drive_to_pos_update(node, agent, dt); } static void __fastcall hook_mission_action(const char *name, const void *blk) @@ -192,7 +188,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 }, + { "drive_to_pos_update", g_lmp.ground_ai_drive_to_pos_update, (void *)&hook_drive_to_pos_update, (void **)&orig_drive_to_pos_update }, }; 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 aea8fef..0762676 100644 --- a/native/wto-net/src/local_mp_values.c +++ b/native/wto-net/src/local_mp_values.c @@ -190,7 +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), + 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), }; diff --git a/native/wto-net/src/local_mp_values.h b/native/wto-net/src/local_mp_values.h index a8d548b..03ac2a8 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, *ground_ai_set_beh_tree; + 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; } LmpValues; diff --git a/patches/native/local_mp_ground_ai.jsonc b/patches/native/local_mp_ground_ai.jsonc index 79c7588..2c6d023 100644 --- a/patches/native/local_mp_ground_ai.jsonc +++ b/patches/native/local_mp_ground_ai.jsonc @@ -63,14 +63,14 @@ } }] }, - // 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": { + // driveToPos::update (vtable[1] of the tankBot driveToPos behavior node). + // 2.61.0.37: 0x861370. 2.61.0.58: 0x863a90. + "ground_ai_drive_to_pos_update": { "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 ?? ?? ?? ??" + "pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 98 02 00 00 44 0f 29 bc 24 80 02 00 00 44 0f 29 b4 24 70 02 00 00 44 0f 29 ac 24 60 02 00 00 44 0f 29 a4 24 50 02 00 00 44 0f 29 9c 24 40 02 00 00 44 0f 29 94 24 30 02 00 00 44 0f 29 8c 24 20 02 00 00 44 0f 29 84 24 10 02 00 00 0f 29 bc 24 00 02 00 00 0f 29 b4 24 f0 01 00 00 44 0f 28 da 49 89 cf 48 8b 3d ?? ?? ?? ?? 44 8b 72 08 0f b6 87 f3 00 00 00 48 8b 9f 60 06 00 00 48 85 db 40 0f 94 c5 40 08 c5 40 f6 c5 01 75 09 48 89 d9 ff 15 ?? ?? ?? ?? 44" } }] }