/* * Which wto_ws.cfg value fills which field of g_lmp, per LocalMP module (local_mp_values.h). The * names are `` and `.` of patches/native/.jsonc. * * A few fields are derived from captured ones where the client has no instruction of its own for * them; each derivation is described in derive_values(). */ #include "local_mp_values.h" #include "hook_config.h" #include #include LmpValues g_lmp; typedef enum LmpValueKind { LMP_ADDRESS, /* an RVA: stored as the address in this process */ LMP_OFFSET, /* a structure offset or size */ LMP_SIGNED, /* a signed displacement */ } LmpValueKind; typedef struct LmpValueSpec { const char *module; const char *name; LmpValueKind kind; size_t field; } LmpValueSpec; #define A(module, name, field) { module, name, LMP_ADDRESS, offsetof(LmpValues, field) } #define O(module, name, field) { module, name, LMP_OFFSET, offsetof(LmpValues, field) } #define S(module, name, field) { module, name, LMP_SIGNED, offsetof(LmpValues, field) } #define CORE "local_mp_core" #define PLAYERS "local_mp_players" #define LOADOUT "local_mp_loadout" #define ACTIONS "local_mp_actions" #define AWARDS "local_mp_awards" #define SCORES "local_mp_scores" #define KILLS "local_mp_kills" #define EVENTS "local_mp_events" #define NUKE "local_mp_nuke" #define SUPPORT "local_mp_support" #define DAMAGE_NOTICES "local_mp_damage_notifications" #define AIR_EVENTS "local_mp_air_events" static const LmpValueSpec SPECS[] = { A(CORE, "do_respawn_player", do_respawn_player), O(CORE, "do_respawn_player.app_score_rules", app_score_rules), A(CORE, "do_respawn_player.hero", hero), A(CORE, "disabled_slots_mask.multiplayer", multiplayer), A(CORE, "disabled_slots_mask.app", app), A(CORE, "disabled_slots_mask.local_mplayer", local_mplayer), O(CORE, "disabled_slots_mask.mplayer_broken_slots", mp_broken_slots), A(CORE, "get_player_country", get_player_country), O(CORE, "get_player_country.mp_is_local_mp", mp_is_local_mp), A(CORE, "get_player_country.player_count", player_count), A(CORE, "get_player_country.player_table", player_table), A(CORE, "sq_local_country.mission_settings", mission_settings), A(CORE, "refl_dtor", refl_dtor), A(CORE, "refl_stdmem.stdmem", stdmem), A(CORE, "aircraft_change_result", aircraft_change_result), O(CORE, "aircraft_change_result.econ_change_req", econ_change_req), A(CORE, "set_player_gui_state", set_player_gui_state), A(CORE, "get_unit_by_eid", get_unit_by_eid), A(CORE, "set_owning_mplayer", set_owning_mplayer), O(CORE, "set_owning_mplayer.mp_pid", mp_pid), A(CORE, "iground_on_dead", iground_on_dead), A(CORE, "datablock_get_str", datablock_get_str), A(CORE, "datablock_set_from", datablock_set_from), A(CORE, "datablock_set_from.dagmem_alloc", dagmem_alloc), A(CORE, "mp_construct_local", mp_construct_local), O(CORE, "mp_construct_local.mp_chat_host", mp_chat_host), O(CORE, "mp_construct_local.mp_is_host", mp_is_host), A(CORE, "gui_state_update", gui_state_update), O(CORE, "app_econ_state.econ_holder", app_econ_holder), O(CORE, "app_econ_state.econ_state", econ_state), O(CORE, "mplayer_matching.match_team", match_team), O(CORE, "mplayer_matching.mp_team", mp_team), O(CORE, "mplayer_matching.mp_user_id", mp_user_id), A(CORE, "unit_change_aircraft", unit_change_aircraft), O(CORE, "unit_type.unit_type", unit_type), O(CORE, "unit_info_name.unit_info", unit_info), O(CORE, "unit_info_name.info_name", unit_info_name), O(CORE, "unit_mplayer.unit_mplayer", unit_mplayer), O(CORE, "mission_custom_bots.custom_bots", mis_custom_bots), O(CORE, "mplayer_unit_eid.unit_eid", mp_unit_eid), A(CORE, "unit_on_event", unit_on_event), A(PLAYERS, "mplayer_init_matching", mplayer_init_matching), A(PLAYERS, "is_slot_ready_at_host", is_slot_ready_at_host), O(PLAYERS, "mplayer_gui_state.gui_state", mp_gui_state), O(PLAYERS, "mplayer_used_spares.used_spares", mp_used_spares), O(PLAYERS, "mission_allies_country.allies_country", mis_allies_country), O(PLAYERS, "mission_axis_country.axis_country", mis_axis_country), O(PLAYERS, "mission_arcade_country.arcade_country", mis_arcade_country), A(LOADOUT, "sem_change_aircraft_send", sem_change_aircraft_send), A(LOADOUT, "refl_ctor", refl_ctor), A(LOADOUT, "datablock_dtor", datablock_dtor), A(LOADOUT, "bullet_vec_assign", bullet_vec_assign), A(LOADOUT, "get_decals_blk", get_decals_blk), A(LOADOUT, "get_attachables_blk", get_attachables_blk), A(LOADOUT, "str_hash_fnv1", str_hash_fnv1), A(LOADOUT, "namemap_add_name_id", namemap_add_name_id), O(LOADOUT, "refl_objects.bullets", refl_bullets), O(LOADOUT, "refl_objects.disabled_mods", refl_disabled_mods), O(LOADOUT, "refl_objects.enabled_mods", refl_enabled_mods), O(LOADOUT, "refl_objects.custom_preset", refl_custom_preset), O(LOADOUT, "refl_objects.attachables", refl_attachables), O(LOADOUT, "refl_objects.decals", refl_decals), O(LOADOUT, "refl_names.custom_skin", refl_custom_skin), O(LOADOUT, "refl_names.skin", refl_skin), O(LOADOUT, "refl_names.weapon", refl_weapon), O(LOADOUT, "refl_names.unit", refl_unit), O(LOADOUT, "refl_flags.flags", refl_flags), O(LOADOUT, "refl_targeting.gun_convergence", refl_gun_convergence), O(LOADOUT, "refl_vertical_targeting.vertical_targeting", refl_vertical_targeting), O(LOADOUT, "refl_bomb_fuse.bomb_fuse", refl_bomb_fuse), O(LOADOUT, "respawn_spawn.resp_base_id", mp_resp_base_id), O(LOADOUT, "respawn_spawn.spawn_delay_a", mp_spawn_delay_a), O(LOADOUT, "unit_spawn_state.spawn_delay_b", mp_spawn_delay_b), O(LOADOUT, "respawn_spawn.spawn_pos_x", mp_spawn_pos_x), O(LOADOUT, "respawn_spawn.spawn_pos_y", mp_spawn_pos_y), O(LOADOUT, "respawn_spawn.spawn_pos_z", mp_spawn_pos_z), O(LOADOUT, "change_req_slot.slot_id", econ_req_slot_id), O(LOADOUT, "change_req_bullets.bullets_begin", econ_req_bullets_begin), O(LOADOUT, "change_req_bullets.bullets_end", econ_req_bullets_end), A(ACTIONS, "mp_init_chat", mp_init_chat), O(ACTIONS, "mp_chat.mp_chat", mp_chat), O(ACTIONS, "mp_team_countries.team1_countries", mp_team1_countries), O(ACTIONS, "mp_team_countries.team2_countries", mp_team2_countries), A(AWARDS, "score_msg_blk_ctor.call", blk_ctor), A(AWARDS, "score_msg_blk_set_str.call", blk_set_str), A(AWARDS, "score_msg_blk_to_owned.call", blk_to_owned), A(AWARDS, "score_msg_blk_set_int.call", blk_set_int), O(AWARDS, "score_msg_hud_queue.queue", gsd_hud_queue), A(AWARDS, "score_msg_hud_queue.call", hud_notify_script), A(AWARDS, "score_msg_blk_dtor.call", blk_dtor), O(AWARDS, "score_msg_exp_class.exp_class", unit_info_exp_class), A(AWARDS, "game_save_data.game_save_data", game_save_data), A(SCORES, "datablock_get_real", datablock_get_real), O(SCORES, "mission_score_params.custom_score_params", mis_custom_score_params), A(KILLS, "mplayer_add_score", mplayer_add_score), O(KILLS, "mplayer_score.score", mp_score), O(KILLS, "mplayer_stat_sync.dirty", mp_stat_dirty), O(KILLS, "mplayer_stat_sync.payload", mp_stat_payload), A(KILLS, "net_mark_dirty", net_mark_dirty), A(KILLS, "on_unit_dead_once", on_unit_dead_once), O(KILLS, "on_unit_dead_once.skip_kill", unit_skip_kill), O(KILLS, "unit_severe.severe_idx", unit_severe_idx), O(KILLS, "unit_severe.severe_uid", unit_severe_uid), O(KILLS, "unit_severe.severe_pid", unit_severe_pid), O(KILLS, "ground_death_flags.already_dead", igm_already_dead), O(KILLS, "ground_death_flags.dead_silent", igm_dead_silent), O(KILLS, "ground_bailout.bailout_dead", igm_bailout_dead), O(KILLS, "ground_offenders.offenders_count", igm_offenders_count), O(KILLS, "ground_offenders.offenders", igm_offenders), O(KILLS, "ground_offenders.offender_size", offender_size), O(KILLS, "ground_offenders.killer", igm_killer), O(KILLS, "ground_offenders.killer_uid", igm_killer_uid), O(KILLS, "ground_offenders.killer_pid", igm_killer_pid), A(KILLS, "iground_award_assists", iground_award_assists), O(KILLS, "iground_award_assists.choose_offender", unit_vtf_choose_offender), O(KILLS, "offender_fields.unit_army", unit_army), O(KILLS, "offender_fields.army", offender_army), O(KILLS, "offender_fields.uid", offender_uid), O(KILLS, "offender_fields.pid", offender_pid), O(KILLS, "stat_kills.field", mp_kills), O(KILLS, "stat_ground_kills.field", mp_ground_kills), O(KILLS, "stat_human_kills.field", mp_human_kills), O(KILLS, "stat_naval_kills.field", mp_naval_kills), O(KILLS, "stat_team_kills.field", mp_team_kills), O(KILLS, "stat_ai_kills.field", mp_ai_kills), O(KILLS, "stat_ai_ground_kills.field", mp_ai_ground_kills), O(KILLS, "stat_ai_naval_kills.field", mp_ai_naval_kills), O(KILLS, "stat_assists.field", mp_assists), O(KILLS, "stat_deaths.field", mp_deaths), O(KILLS, "stat_capture_zone.field", mp_capture_zone), O(KILLS, "stat_score.fallback", mp_fallback_score), 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, "caller_hit_crit.call", dispatch_hit_crit), 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(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), S(NUKE, "mission_vars_walk.entry_bias", mission_var_bias), S(NUKE, "mission_vars_step.name", mission_var_name_disp), O(NUKE, "mission_vars_step.stride", mission_var_stride), S(NUKE, "mission_vars_value.value", mission_var_value_disp), A(SUPPORT, "set_controlled_unit", set_controlled_unit), O(SUPPORT, "mplayer_support_unit.eid", mp_support_unit_eid), O(SUPPORT, "mplayer_support_unit.unit", mp_support_unit_ptr), A(DAMAGE_NOTICES, "barrel_damage", barrel_damage), O(DAMAGE_NOTICES, "barrel_damage.unit", barrel_unit_ref), A(DAMAGE_NOTICES, "barrel_damage_notice.deliver", barrel_notice_deliver), O(DAMAGE_NOTICES, "barrel_damage_notice.id", barrel_notice_id), A(DAMAGE_NOTICES, "breech_fire_update", breech_fire_update), O(DAMAGE_NOTICES, "breech_fire_update.unit", breech_unit), A(DAMAGE_NOTICES, "breech_damage_notice.deliver", breech_notice_deliver), O(DAMAGE_NOTICES, "breech_damage_notice.id", breech_notice_id), A(DAMAGE_NOTICES, "mplayer_controlled_unit", mplayer_controlled_unit), A(DAMAGE_NOTICES, "hud_damage_deliver", hud_damage_deliver), A(DAMAGE_NOTICES, "avionics_damage", avionics_damage), O(DAMAGE_NOTICES, "avionics_damage.unit", avionics_unit), A(DAMAGE_NOTICES, "avionics_exit_optic.call", avionics_exit_optic), O(DAMAGE_NOTICES, "hit_event_offender.offender", hit_event_offender), A(DAMAGE_NOTICES, "hit_watched_hero.watched_hero", watched_hero), A(DAMAGE_NOTICES, "hit_parts_feedback.enqueue_enemy_parts", enqueue_enemy_parts), A(DAMAGE_NOTICES, "hit_parts_feedback.hit_cam_important", hit_cam_important), A(DAMAGE_NOTICES, "hit_parts_feedback.naval_hit_state", naval_hit_state), 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), A(AIR_EVENTS, "kill_streak_rules.gameplay", gameplay), O(AIR_EVENTS, "kill_streak_rules.rule_count", gp_ks_rule_count), O(AIR_EVENTS, "kill_streak_rules.rules", gp_ks_rules), O(AIR_EVENTS, "kill_streak_rules.rule_tag", ks_rule_tag), A(AIR_EVENTS, "kill_streak_rules.name_map", kill_streak_name_map), A(AIR_EVENTS, "add_kill_streak_points", add_kill_streak_points), O(AIR_EVENTS, "mplayer_streak_progress.progress", mp_ks_progress), O(AIR_EVENTS, "kill_streak_ai_mults.air_ai_mult", ks_rule_air_ai_mult), O(AIR_EVENTS, "kill_streak_ai_mults.ground_ai_mult", ks_rule_ground_ai_mult), A(AIR_EVENTS, "air_event_spawn_table.battle_center", air_event_battle_center), O(AIR_EVENTS, "air_event_spawn_table.spawn_pos_count", ks_rule_spawn_pos_count), A(AIR_EVENTS, "air_event_spawn_table.max_rank", mission_max_rank), O(AIR_EVENTS, "air_event_spawn_table.spawn_pos", ks_rule_spawn_pos), O(AIR_EVENTS, "air_event_spawn_table.spawn_pos_stride", ks_spawn_pos_stride), O(AIR_EVENTS, "air_event_terrain.app_terrain", app_terrain), A(AIR_EVENTS, "air_event_terrain.terrain_height", air_event_terrain_height), A(AIR_EVENTS, "air_event_switch_unit", air_event_switch_unit), A(AIR_EVENTS, "air_event_orientation.call", air_event_orientation), A(AIR_EVENTS, "send_unit_respawn", send_unit_respawn), A(AIR_EVENTS, "send_unit_respawn_broadcast.mpi_sendto", mpi_sendto), }; static void store(const LmpValueSpec *spec, int64_t value, uint8_t *base) { uint8_t *field = (uint8_t *)&g_lmp + spec->field; if (spec->kind == LMP_ADDRESS) { uint8_t *address = base + value; memcpy(field, &address, sizeof(address)); } else if (spec->kind == LMP_SIGNED) { ptrdiff_t signed_value = (ptrdiff_t)value; memcpy(field, &signed_value, sizeof(signed_value)); } else { size_t offset = (size_t)value; memcpy(field, &offset, sizeof(offset)); } } /* * Fields the client reads nowhere at a fixed displacement of its own: * - the change request members are captured as offsets in the economic state, which is how the * client addresses them, and used relative to the request; * - the reflection fuel is the float before the gun convergence in the block the reflection * constructor initialises as one (+0xd0..+0xdf on 2.61.0.37); no client code reads it; * - the ground model's killer army is the army member of the killer record embedded in it; * - a mission variable's name and value are where the walk's displacements point from the * pointer it keeps `entry_bias` bytes into each entry. */ static void derive_values(const char *module) { if (strcmp(module, LOADOUT) == 0) { g_lmp.req_slot_id = g_lmp.econ_req_slot_id - g_lmp.econ_change_req; g_lmp.req_bullets_begin = g_lmp.econ_req_bullets_begin - g_lmp.econ_change_req; g_lmp.req_bullets_end = g_lmp.econ_req_bullets_end - g_lmp.econ_change_req; g_lmp.refl_fuel = g_lmp.refl_gun_convergence - sizeof(float); } else if (strcmp(module, KILLS) == 0) { g_lmp.igm_killer_army = g_lmp.igm_killer + g_lmp.offender_army; } else if (strcmp(module, NUKE) == 0) { g_lmp.mission_var_name = (size_t)(g_lmp.mission_var_bias + g_lmp.mission_var_name_disp); g_lmp.mission_var_value = (size_t)(g_lmp.mission_var_bias + g_lmp.mission_var_value_disp); } } int lmp_values_load(const char *module) { uint8_t *base = (uint8_t *)GetModuleHandleW(NULL); size_t i; for (i = 0; i < sizeof(SPECS) / sizeof(SPECS[0]); i++) { int64_t value; if (strcmp(SPECS[i].module, module) != 0) continue; if (!config_native_value(SPECS[i].name, &value)) { log_line("local_mp: %s unavailable: no value %s in wto_ws.cfg", module, SPECS[i].name); return 0; } store(&SPECS[i], value, base); } derive_values(module); return 1; }