fix(ground-ai): short-circuit driveToPos instead of skipping setBehaviorTree
Skipping Unit::setBehaviorTree left unit->behTree null on LocalMP bot tanks, which prevented VehiclePhysActor from applying producedCT to appliedCT (100% dead_echo in sinai_Conq1). Hook driveToPos::update (.37 0x861370, .58 0x863a90) instead and return ER_SUCCESS (1) when the ground AI script is ready, keeping the BehTree initialized while completely suppressing stock tankBot driving. Verified MSVC build (0 warnings) and .37/.58 native module resolution (0 failures).
This commit is contained in:
1 parent
85532cd930
commit
b3f9ff589c
4 files changed
+15
-19
No files matched your search
@@ -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;
|
||||
|
||||
@@ -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),
|
||||
};
|
||||
|
||||
@@ -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;
|
||||
|
||||
|
||||
Reference in new issue
Block a user