fix(battle): award Air Arcade mini-base score
Use the native health update identified in PR #10 to report enemy mini-base damage and destruction. Preserve fractional personal score across hits and use the selected mode to gate both the HUD reward and settlement. Verified server and launcher types, MSVC compilation, Quirrel bytecode, and patch resolution on 2.61.0.37, 2.61.0.58, and 2.61.0.60. In-game acceptance is pending. Co-authored-by: duduyagame <[email protected]>
This commit is contained in:
1 parent
194417a388
commit
6d0abf9caf
19 files changed
+257
-27
No files matched your search
@@ -23,7 +23,7 @@ New-Item -ItemType Directory -Force $obj | Out-Null
|
||||
$sources = @(
|
||||
"$src\dll_main.c", "$src\hook_config.c", "$src\redirect_rules.c", "$src\resolver_hooks.c", "$src\connection_hooks.c",
|
||||
"$src\local_mp_core.c", "$src\local_mp_values.c", "$src\local_mp_players.c", "$src\local_mp_loadout.c", "$src\local_mp_actions.c", "$src\local_mp_awards.c", "$src\local_mp_kills.c", "$src\local_mp_events.c", "$src\local_mp_scores.c", "$src\local_mp_nuke.c", "$src\local_mp_support.c",
|
||||
"$src\local_mp_damage_notifications.c", "$src\local_mp_air_events.c", "$src\local_mp_ground_ai.c",
|
||||
"$src\local_mp_damage_notifications.c", "$src\local_mp_air_events.c", "$src\local_mp_ground_ai.c", "$src\local_mp_zones.c",
|
||||
"$mh\src\hook.c", "$mh\src\buffer.c", "$mh\src\trampoline.c", "$mh\src\hde\hde64.c"
|
||||
) | ForEach-Object { '"' + (Resolve-Path $_) + '"' }
|
||||
|
||||
|
||||
@@ -139,6 +139,7 @@ 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_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 },
|
||||
|
||||
@@ -25,11 +25,11 @@ typedef const char *(__fastcall *LmpDataBlockGetStrFn)(const void *blk, const ch
|
||||
/* One combat event of the local player, as facts only (see local_mp_awards.c). */
|
||||
typedef struct LocalMpAwardEvent {
|
||||
uint32_t exp_event; /* EXP_EVENT_* code (globalScripts/expEventConsts.nut) */
|
||||
const uint8_t *victim; /* destroyed or damaged unit; NULL for a zone capture */
|
||||
const uint8_t *victim; /* destroyed or damaged unit; NULL for zone events */
|
||||
int victim_is_player; /* victim belongs to an MPlayer (player or bound bot) */
|
||||
int friendly; /* victim was on the local player's team */
|
||||
const char *modifier; /* stock messageModifier, e.g. "from_severe_damage", or NULL */
|
||||
int32_t damage; /* naval award damage for EXP_EVENT_UNIT_DAMAGE, else 0 */
|
||||
int32_t damage; /* naval damage points or bombing zone health in basis points */
|
||||
} LocalMpAwardEvent;
|
||||
|
||||
extern uint8_t **g_local_mp_multiplayer;
|
||||
@@ -81,6 +81,7 @@ void local_mp_events_begin_death(const uint8_t *victim);
|
||||
|
||||
/* Shared MPlayer scoreboard helpers exposed by local_mp_kills.c. */
|
||||
void local_mp_add_mplayer_score(uint8_t *mp, float delta, uint32_t event_id);
|
||||
void local_mp_add_personal_score(uint8_t *mp, float delta, uint32_t event_id);
|
||||
void local_mp_mark_mplayer_dirty(uint8_t *mp);
|
||||
void local_mp_inc_mplayer_stat(uint8_t *mp, size_t off);
|
||||
|
||||
@@ -105,6 +106,8 @@ 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_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);
|
||||
@@ -47,7 +47,7 @@ static void dec_mplayer_stat_pos(uint8_t *mp, size_t off)
|
||||
*(int16_t *)(mp + off) = (int16_t)(v - 1);
|
||||
}
|
||||
|
||||
void local_mp_add_mplayer_score(uint8_t *mp, float delta, uint32_t event_id)
|
||||
static void add_mplayer_score(uint8_t *mp, float delta, uint32_t event_id, uint8_t add_team)
|
||||
{
|
||||
uint8_t *app = g_local_mp_app ? *g_local_mp_app : NULL;
|
||||
int32_t total;
|
||||
@@ -55,11 +55,21 @@ void local_mp_add_mplayer_score(uint8_t *mp, float delta, uint32_t event_id)
|
||||
return;
|
||||
if (app == NULL || *(void **)(app + LMP_APP_OFF_SCORE_RULES) == NULL)
|
||||
return;
|
||||
fn_mplayer_add_score(mp, delta, event_id, 1);
|
||||
fn_mplayer_add_score(mp, delta, event_id, add_team);
|
||||
total = *(int32_t *)(mp + LMP_MP_OFF_SCORE);
|
||||
*(int16_t *)(mp + LMP_MP_OFF_FALLBACK_SCORE) = (total > 32767) ? (int16_t)32767 : (int16_t)total;
|
||||
}
|
||||
|
||||
void local_mp_add_mplayer_score(uint8_t *mp, float delta, uint32_t event_id)
|
||||
{
|
||||
add_mplayer_score(mp, delta, event_id, 1);
|
||||
}
|
||||
|
||||
void local_mp_add_personal_score(uint8_t *mp, float delta, uint32_t event_id)
|
||||
{
|
||||
add_mplayer_score(mp, delta, event_id, 0);
|
||||
}
|
||||
|
||||
static int is_same_severe_offender(const uint8_t *victim, const uint8_t *killer_mp)
|
||||
{
|
||||
if (victim == NULL || killer_mp == NULL || *(const int16_t *)(victim + LMP_UNIT_OFF_SEVERE_IDX) == -1)
|
||||
|
||||
@@ -20,10 +20,12 @@
|
||||
#define LMP_GUI_STATE_CA_READY 8
|
||||
|
||||
#define LMP_EXP_EVENT_CAPTURE_ZONE 2u
|
||||
#define LMP_EXP_EVENT_DESTROY_ZONE 3u
|
||||
#define LMP_EXP_EVENT_KILL 5u
|
||||
#define LMP_EXP_EVENT_KILL_GROUND 6u
|
||||
#define LMP_EXP_EVENT_ASSIST 9u
|
||||
#define LMP_EXP_EVENT_HIT 13u
|
||||
#define LMP_EXP_EVENT_DAMAGE_ZONE 17u
|
||||
#define LMP_EXP_EVENT_INEFFECTIVE_HIT 20u
|
||||
#define LMP_EXP_EVENT_UNIT_DAMAGE 24u
|
||||
#define LMP_EXP_EVENT_SEVERE_DAMAGE 35u
|
||||
|
||||
@@ -111,6 +111,7 @@ static void __fastcall hook_mplayer_init_from_matching(uint8_t *mplayer, uint8_t
|
||||
if (*(int32_t *)(info + LMP_MATCH_INFO_OFF_SQUAD_ID) == 0)
|
||||
*(int32_t *)(info + LMP_MATCH_INFO_OFF_SQUAD_ID) = 1;
|
||||
local_mp_events_reset();
|
||||
local_mp_zones_reset();
|
||||
log_line("local_mp: initialized local player team=%d squad=%d",
|
||||
(int)(*(int32_t *)(info + LMP_MATCH_INFO_OFF_TEAM)),
|
||||
(int)(*(int32_t *)(info + LMP_MATCH_INFO_OFF_SQUAD_ID)));
|
||||
|
||||
@@ -9,6 +9,8 @@
|
||||
* group: ground, air, naval, human (the victim's; the capturer's own
|
||||
* for capture)
|
||||
* wtoScore_damagePerPoint naval award damage
|
||||
* wtoScore_zoneDamage health removed from an enemy mini-base in Air Arcade
|
||||
* wtoScore_zoneDestruction final hit on an enemy mini-base in Air Arcade
|
||||
* wtoScore_aiMul victims that are not players (warpoints.blk aiKillK)
|
||||
* A missing key scores 0, so nothing here carries a score of its own.
|
||||
*/
|
||||
|
||||
@@ -37,6 +37,7 @@ typedef struct LmpValueSpec {
|
||||
#define SCORES "local_mp_scores"
|
||||
#define KILLS "local_mp_kills"
|
||||
#define EVENTS "local_mp_events"
|
||||
#define ZONES "local_mp_zones"
|
||||
#define NUKE "local_mp_nuke"
|
||||
#define SUPPORT "local_mp_support"
|
||||
#define DAMAGE_NOTICES "local_mp_damage_notifications"
|
||||
@@ -44,6 +45,11 @@ typedef struct LmpValueSpec {
|
||||
#define GROUND_AI "local_mp_ground_ai"
|
||||
|
||||
static const LmpValueSpec SPECS[] = {
|
||||
A(ZONES, "apply_zone_damage", apply_zone_damage),
|
||||
O(ZONES, "zone_damage_health.health", zone_health), O(ZONES, "zone_damage_health.max_health", zone_max_health),
|
||||
O(ZONES, "zone_damage_team.team", zone_team),
|
||||
O(ZONES, "zone_damage_airfield.flags", zone_flags), O(ZONES, "zone_damage_airfield.airfield_mask", zone_airfield_mask),
|
||||
|
||||
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),
|
||||
|
||||
@@ -82,6 +82,10 @@ 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_zones */
|
||||
uint8_t *apply_zone_damage;
|
||||
size_t zone_health, zone_max_health, zone_team, zone_flags, zone_airfield_mask;
|
||||
|
||||
/* local_mp_air_events */
|
||||
uint8_t *prepare_local_mission, *use_kill_streaks, *gameplay, *kill_streak_name_map, *add_kill_streak_points;
|
||||
uint8_t *air_event_battle_center, *mission_max_rank, *air_event_terrain_height, *air_event_switch_unit;
|
||||
|
||||
@@ -0,0 +1,90 @@
|
||||
/* Observe the stock health update for enemy bombing zones in LocalMP Air Arcade. */
|
||||
#include "local_mp_internal.h"
|
||||
#include "local_mp_offsets.h"
|
||||
|
||||
#include <math.h>
|
||||
|
||||
/* DAMAGE_ZONE uses basis points of the zone's full health, as read by BattleEconomy. */
|
||||
#define ZONE_HEALTH_SCALE 10000
|
||||
|
||||
typedef void (__fastcall *ApplyZoneDamageFn)(uint8_t *zone, const uint8_t *offender, float damage, float contribution);
|
||||
static ApplyZoneDamageFn orig_apply_zone_damage;
|
||||
static int32_t damage_score_remainder;
|
||||
|
||||
void local_mp_zones_reset(void)
|
||||
{
|
||||
damage_score_remainder = 0;
|
||||
}
|
||||
|
||||
static uint8_t *local_zone_attacker(const uint8_t *zone, const uint8_t *offender)
|
||||
{
|
||||
if (zone == NULL || offender == NULL || *(const uint16_t *)offender == UINT16_MAX)
|
||||
return NULL;
|
||||
if ((*(const uint16_t *)(zone + g_lmp.zone_flags) & g_lmp.zone_airfield_mask) != 0)
|
||||
return NULL;
|
||||
|
||||
int zone_team = zone[g_lmp.zone_team];
|
||||
int attacker_team = *(const int32_t *)(offender + LMP_OFFENDER_OFF_ARMY);
|
||||
if ((zone_team != 1 && zone_team != 2) || attacker_team != 3 - zone_team)
|
||||
return NULL;
|
||||
uint8_t *mp = local_mp_find_mplayer(*(const int64_t *)(offender + LMP_OFFENDER_OFF_UID), offender[LMP_OFFENDER_OFF_PID]);
|
||||
return local_mp_is_local_mplayer(mp) && mp[LMP_MP_OFF_TEAM] == attacker_team ? mp : NULL;
|
||||
}
|
||||
|
||||
static void report_zone_award(uint8_t *mp, uint32_t code, int32_t score, int32_t damage)
|
||||
{
|
||||
LocalMpAwardEvent award = { code, NULL, 0, 0, NULL, damage };
|
||||
if (score > 0) {
|
||||
local_mp_add_personal_score(mp, (float)score, code);
|
||||
local_mp_mark_mplayer_dirty(mp);
|
||||
}
|
||||
local_mp_report_award_event(&award);
|
||||
}
|
||||
|
||||
static void award_zone_damage(uint8_t *mp, float before, float after, float max_health, int32_t full_score)
|
||||
{
|
||||
int32_t previous = (int32_t)(before / max_health * ZONE_HEALTH_SCALE + 0.5f);
|
||||
int32_t remaining = (int32_t)(after / max_health * ZONE_HEALTH_SCALE + 0.5f);
|
||||
int32_t lost = previous - remaining;
|
||||
if (lost <= 0)
|
||||
return;
|
||||
|
||||
/* MPlayer::addScore truncates every delta. Carry fractional points across hits. */
|
||||
int64_t scaled = (int64_t)full_score * lost + damage_score_remainder;
|
||||
damage_score_remainder = (int32_t)(scaled % ZONE_HEALTH_SCALE);
|
||||
report_zone_award(mp, LMP_EXP_EVENT_DAMAGE_ZONE, (int32_t)(scaled / ZONE_HEALTH_SCALE), lost);
|
||||
}
|
||||
|
||||
static void __fastcall hook_apply_zone_damage(uint8_t *zone, const uint8_t *offender, float damage, float contribution)
|
||||
{
|
||||
uint8_t *mp = NULL;
|
||||
if (local_mp_is_host() && isfinite(damage) && damage > 0)
|
||||
mp = local_zone_attacker(zone, offender);
|
||||
int32_t damage_score = mp ? (int32_t)local_mp_score_param("wtoScore_zoneDamage") : 0;
|
||||
int32_t destroy_score = mp ? (int32_t)local_mp_score_param("wtoScore_zoneDestruction") : 0;
|
||||
if (damage_score <= 0 && destroy_score <= 0) {
|
||||
orig_apply_zone_damage(zone, offender, damage, contribution);
|
||||
return;
|
||||
}
|
||||
|
||||
float before = *(const float *)(zone + g_lmp.zone_health);
|
||||
float max_health = *(const float *)(zone + g_lmp.zone_max_health);
|
||||
orig_apply_zone_damage(zone, offender, damage, contribution);
|
||||
|
||||
float after = *(const float *)(zone + g_lmp.zone_health);
|
||||
if (!isfinite(max_health) || !(before <= max_health && after >= 0 && after < before) ||
|
||||
*(const float *)(zone + g_lmp.zone_max_health) != max_health)
|
||||
return;
|
||||
if (damage_score > 0)
|
||||
award_zone_damage(mp, before, after, max_health, damage_score);
|
||||
if (destroy_score > 0 && after == 0)
|
||||
report_zone_award(mp, LMP_EXP_EVENT_DESTROY_ZONE, destroy_score, 0);
|
||||
}
|
||||
|
||||
int install_local_mp_zone_hooks(void)
|
||||
{
|
||||
const LocalMpHookSpec hook = {
|
||||
"apply_zone_damage", g_lmp.apply_zone_damage, (void *)&hook_apply_zone_damage, (void **)&orig_apply_zone_damage,
|
||||
};
|
||||
return local_mp_queue_hooks("local_mp_zones", &hook, 1);
|
||||
}
|
||||
Reference in new issue
Block a user