refactor(native): limit the LocalMP bridge to engine gaps
- Scoreboard scores come from the local service: BattleEconomy missionScores() writes the official mission scores into the stock mission block customScoreParams, which the client copies into MissionSettings+0x6d8 without reading it; local_mp_scores.c reads them with DataBlock::getReal. The hardcoded scores and the death score go. - countActivePlayers already counts players with a living vehicle; the only LocalMP gap is its filter skipping bots (MPlayer+0x1d8 bit 7). A one-byte exe patch drops that filter bit instead of a rewrite hook. - ucavLaunch returns early on a host; an exe patch skips that return instead of clearing the global host flag around the call. - onBecameDead no longer runs with isLocalMP cleared: that only queued an EventOnPlayerDeath stock LocalMP skips on purpose, and broke the local player id remap inside the function. - The host chat object keeps its two-field layout, now documented from the host chat handler that reads it.
This commit is contained in:
1 parent
6ac67f1d2a
commit
e3c5880023
17 files changed
+216
-120
No files matched your search
@@ -0,0 +1,8 @@
|
||||
// Masked signature of ucavLaunch from its prologue to the g_multiplayer->isHost early return, 0x35
|
||||
// bytes; the rip-relative load of g_multiplayer and the branch targets are wildcards.
|
||||
// 2.61.0.37: unique hit at 0x101ccd0, edited instruction (jne to the return) at +51 (0x101cd03).
|
||||
{
|
||||
"method": "signature",
|
||||
"section": ".text",
|
||||
"pattern": "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 18 02 00 00 0f 29 bc 24 00 02 00 00 0f 29 b4 24 f0 01 00 00 48 8b 05 ?? ?? ?? ?? 48 85 c0 74 ?? 80 78 60 00 75 ??"
|
||||
}
|
||||
@@ -0,0 +1,25 @@
|
||||
// Let the LocalMP host launch a UCAV (the light tank recon drone and the strike UCAV) from its vehicle.
|
||||
// Why the exe: ucavLaunch returns at once when g_multiplayer->isHost is set, because on a dedicated
|
||||
// server the launch is handled by server code that the client build does not contain; a LocalMP host
|
||||
// is that server. Nothing outside the function decides it.
|
||||
// Without it: pressing the drone key on a LocalMP host does nothing.
|
||||
{
|
||||
"id": "battle/allow-local-host-ucav-launch",
|
||||
"title": "Let a LocalMP host launch UCAVs",
|
||||
"features": [
|
||||
"K-侦察"
|
||||
],
|
||||
"requires": [],
|
||||
"verified_on": [
|
||||
"2.61.0.37"
|
||||
],
|
||||
"edit": {
|
||||
"offset": 51,
|
||||
"asm": [
|
||||
"nop",
|
||||
"nop"
|
||||
],
|
||||
"bytes": "9090",
|
||||
"expect_original": "753a"
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,7 @@
|
||||
// Masked signature of countActivePlayers (prologue through the player filter mask), 0x1b bytes.
|
||||
// 2.61.0.37: unique hit at 0x11b9b60, edited instruction (or eax, 0x3a) at +24 (0x11b9b78).
|
||||
{
|
||||
"method": "signature",
|
||||
"section": ".text",
|
||||
"pattern": "41 57 41 56 41 54 56 57 53 48 83 ec 38 89 cf 80 f2 01 0f b6 c2 c1 e0 0a 83 c8 3a"
|
||||
}
|
||||
@@ -0,0 +1,26 @@
|
||||
// Count AI players in countActivePlayers, the player count that domination ticket bleed and the
|
||||
// battle's player-count rules use.
|
||||
// Why the exe: the stock count walks MPlayers with a filter that skips bots (MPlayer+0x1d8 bit 7,
|
||||
// "isBot"), because online battles have human players only; in a LocalMP battle the AI players take
|
||||
// the human players' places, so the filter would count the AI team as empty. The filter is an
|
||||
// immediate in the function; nothing outside it can change it.
|
||||
// Without it: the AI team counts as having no active players.
|
||||
{
|
||||
"id": "battle/count-bots-as-active-players",
|
||||
"title": "Count AI players as active players in LocalMP battles",
|
||||
"features": [
|
||||
"K-击杀、助攻、占点计分"
|
||||
],
|
||||
"requires": [],
|
||||
"verified_on": [
|
||||
"2.61.0.37"
|
||||
],
|
||||
"edit": {
|
||||
"offset": 24,
|
||||
"asm": [
|
||||
"or eax, 0x32"
|
||||
],
|
||||
"bytes": "83c832",
|
||||
"expect_original": "83c83a"
|
||||
}
|
||||
}
|
||||
@@ -22,7 +22,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_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_core.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",
|
||||
"$mh\src\hook.c", "$mh\src\buffer.c", "$mh\src\trampoline.c", "$mh\src\hde\hde64.c"
|
||||
) | ForEach-Object { '"' + (Resolve-Path $_) + '"' }
|
||||
|
||||
|
||||
@@ -1,7 +1,13 @@
|
||||
/*
|
||||
* LocalMP multi-nation team country lists (`team1_countries` / `team2_countries`),
|
||||
* MPChat / MPChatHost initialization, UCAV recon drone bridge, and active-player count
|
||||
* bridge for CTA ticket bleed rules.
|
||||
* LocalMP multi-nation team country lists (`team1_countries` / `team2_countries`) and the
|
||||
* in-battle chat objects of the host.
|
||||
*
|
||||
* Chat (2.61.0.37): when the host sends a message, chat_on_send (0x154f540) hands it to the host
|
||||
* chat handler 0x133ba10 with Multiplayer+0x1f8 as its object instead of sending it to a server.
|
||||
* The client never creates that object (a dedicated server does); the handler reads exactly two
|
||||
* fields of it: [0] the Multiplayer and [1] an optional chat log writer, used only when non-null
|
||||
* (0x133c40f). The host here gets that two-field object with no log writer, and its MPChat
|
||||
* (Multiplayer+0x1f0) from the stock Multiplayer::initMPChat (0x5bd6a0).
|
||||
*/
|
||||
#include "hooks.h"
|
||||
#include "hook_config.h"
|
||||
@@ -17,14 +23,10 @@
|
||||
typedef uint8_t (__fastcall *MpConstructLocalFn)(uint8_t *mp, void *mis, void *chat_settings);
|
||||
typedef void (__fastcall *MpInitChatFn)(uint8_t *mp, void *chat_settings);
|
||||
typedef void *(__fastcall *DagmemAllocFn)(size_t size);
|
||||
typedef int64_t (__fastcall *UcavLaunchFn)(void *a1, void *a2, void *a3, void *a4);
|
||||
typedef int32_t (__fastcall *CountActivePlayersFn)(int32_t team, uint8_t include_connecting);
|
||||
|
||||
static MpConstructLocalFn orig_mp_construct_local;
|
||||
static MpInitChatFn fn_mp_init_chat;
|
||||
static DagmemAllocFn fn_dagmem_alloc;
|
||||
static UcavLaunchFn orig_ucav_launch;
|
||||
static CountActivePlayersFn orig_count_active_players;
|
||||
|
||||
static void clear_team_country_tab(uint8_t *tab)
|
||||
{
|
||||
@@ -115,91 +117,26 @@ static uint8_t __fastcall hook_mp_construct_local(uint8_t *mp, void *mis, void *
|
||||
chat_host[0] = mp;
|
||||
chat_host[1] = NULL;
|
||||
*(void **)(mp + LMP_MP_MGR_OFF_CHAT_HOST) = chat_host;
|
||||
log_line("local_mp: created the host chat object for LocalMP");
|
||||
}
|
||||
}
|
||||
log_line("local_mp: initialized multi-nation bot teams and MPChat for LocalMP");
|
||||
return ok;
|
||||
}
|
||||
|
||||
static int64_t __fastcall hook_ucav_launch(void *a1, void *a2, void *a3, void *a4)
|
||||
{
|
||||
int64_t res;
|
||||
|
||||
if (!local_mp_is_host())
|
||||
return orig_ucav_launch(a1, a2, a3, a4);
|
||||
|
||||
(*g_local_mp_multiplayer)[LMP_MP_MGR_OFF_IS_HOST] = 0;
|
||||
res = orig_ucav_launch(a1, a2, a3, a4);
|
||||
if (*g_local_mp_multiplayer != NULL)
|
||||
(*g_local_mp_multiplayer)[LMP_MP_MGR_OFF_IS_HOST] = 1;
|
||||
return res;
|
||||
}
|
||||
|
||||
static int is_unit_alive_for_tickets(uint32_t eid)
|
||||
{
|
||||
uint8_t *unit;
|
||||
|
||||
if (eid == 0 || g_lmp_get_unit_by_eid == NULL)
|
||||
return 0;
|
||||
unit = (uint8_t *)g_lmp_get_unit_by_eid(eid);
|
||||
if (unit == NULL || *(uint16_t *)(unit + LMP_UNIT_OFF_BAIL_STATE) != 0)
|
||||
return 0;
|
||||
if (*(uint32_t *)(unit + LMP_UNIT_OFF_ALIVE_STATE) == 0 &&
|
||||
*(uint16_t *)(unit + LMP_UNIT_OFF_TYPE) != LMP_UNIT_TYPE_HELICOPTER)
|
||||
return 0;
|
||||
return (*(uint32_t *)(unit + LMP_UNIT_OFF_DEAD_FLAGS) & LMP_UNIT_DEAD_FLAGS_MASK) == 0;
|
||||
}
|
||||
|
||||
static int32_t __fastcall hook_count_active_players(int32_t team, uint8_t include_connecting)
|
||||
{
|
||||
uint8_t **table;
|
||||
uint32_t count;
|
||||
uint32_t i;
|
||||
int32_t alive = 0;
|
||||
|
||||
if (!local_mp_is_host())
|
||||
return orig_count_active_players(team, include_connecting);
|
||||
|
||||
table = g_local_mp_player_table ? *g_local_mp_player_table : NULL;
|
||||
count = g_local_mp_player_count ? *g_local_mp_player_count : 0;
|
||||
if (table == NULL || count == 0)
|
||||
return orig_count_active_players(team, include_connecting);
|
||||
|
||||
for (i = 0; i < count; i++) {
|
||||
uint8_t *mp = table[i];
|
||||
if (mp == NULL)
|
||||
continue;
|
||||
if ((*(uint32_t *)(mp + LMP_MP_OFF_FLAGS) & LMP_MP_FLAG_SPECTATOR_MASK) != 0)
|
||||
continue;
|
||||
if (team > 0 && mp[LMP_MP_OFF_TEAM] != (uint8_t)team)
|
||||
continue;
|
||||
if (is_unit_alive_for_tickets(*(uint32_t *)(mp + LMP_MP_OFF_UNIT_EID)) ||
|
||||
is_unit_alive_for_tickets(*(uint32_t *)(mp + LMP_MP_OFF_SUPPORT_UNIT_EID)))
|
||||
alive++;
|
||||
}
|
||||
return alive;
|
||||
}
|
||||
|
||||
int install_local_mp_action_hooks(const uint8_t *text, size_t text_size)
|
||||
{
|
||||
uint8_t *p_construct = local_mp_scan_unique(text, text_size, "Multiplayer::constructLocalMP", LMP_SIG_MP_CONSTRUCT_LOCAL);
|
||||
uint8_t *p_init_chat = local_mp_scan_unique(text, text_size, "Multiplayer::initMPChat", LMP_SIG_MP_INIT_CHAT);
|
||||
uint8_t *p_set_from = local_mp_scan_unique(text, text_size, "DataBlock::setFrom", LMP_SIG_DATABLOCK_SET_FROM);
|
||||
uint8_t *p_ucav = local_mp_scan_unique(text, text_size, "ucavLaunch", LMP_SIG_UCAV_LAUNCH);
|
||||
uint8_t *p_count_active = local_mp_scan_unique(text, text_size, "countActivePlayers", LMP_SIG_COUNT_ACTIVE_PLAYERS);
|
||||
|
||||
if (!p_construct || !p_init_chat || !p_set_from || !p_ucav || !p_count_active)
|
||||
if (!p_construct || !p_init_chat || !p_set_from)
|
||||
return 0;
|
||||
fn_mp_init_chat = (MpInitChatFn)p_init_chat;
|
||||
fn_dagmem_alloc = (DagmemAllocFn)local_mp_resolve_rip(p_set_from + 0x25, 1, 5);
|
||||
|
||||
if (MH_CreateHook(p_construct, (void *)&hook_mp_construct_local, (void **)&orig_mp_construct_local) != MH_OK ||
|
||||
MH_EnableHook(p_construct) != MH_OK ||
|
||||
MH_CreateHook(p_ucav, (void *)&hook_ucav_launch, (void **)&orig_ucav_launch) != MH_OK ||
|
||||
MH_EnableHook(p_ucav) != MH_OK ||
|
||||
MH_CreateHook(p_count_active, (void *)&hook_count_active_players, (void **)&orig_count_active_players) != MH_OK ||
|
||||
MH_EnableHook(p_count_active) != MH_OK) {
|
||||
log_line("local_mp: failed to install action or active-player hooks");
|
||||
MH_EnableHook(p_construct) != MH_OK) {
|
||||
log_line("local_mp: failed to install the LocalMP construction hook");
|
||||
return 0;
|
||||
}
|
||||
return 1;
|
||||
|
||||
@@ -282,7 +282,8 @@ void install_local_mp_hooks(void)
|
||||
!install_local_mp_action_hooks(text, text_size) ||
|
||||
!install_local_mp_award_hooks(text, text_size, p_ground_dead) ||
|
||||
!install_local_mp_kill_hooks(text, text_size, p_ground_dead) ||
|
||||
!install_local_mp_event_hooks(text, text_size)) {
|
||||
!install_local_mp_event_hooks(text, text_size) ||
|
||||
!install_local_mp_score_reader(text, text_size)) {
|
||||
log_line("local_mp: one or more LocalMP subsystem hooks failed to initialize");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -5,6 +5,7 @@
|
||||
* `IGroundModel::onBecameDead` calls both `IGroundModel::awardAssists` (`0x465540`) and
|
||||
* `Unit::awardAssists` (`0xe5b200` -> `dispatchAssist` `0x35beb0`); deduplicating `(victim, mp)`
|
||||
* per unit death ensures every assist across air, ground, and naval is credited strictly once.
|
||||
* Scores come from the mission settings (local_mp_scores.c).
|
||||
*/
|
||||
#include "hooks.h"
|
||||
#include "hook_config.h"
|
||||
@@ -15,13 +16,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define SCORE_SEVERE_DAMAGE 160.0f
|
||||
#define SCORE_PVP_ASSIST 100.0f
|
||||
#define SCORE_AI_UNIT_ASSIST 30.0f
|
||||
#define SCORE_CAPTURE_ZONE 300.0f
|
||||
#define SCORE_CRITICAL_HIT 50.0f
|
||||
#define SCORE_HIT 10.0f
|
||||
#define SCORE_NAVAL_DMG_FACTOR 0.08f
|
||||
#define MAX_OFFENDER_SNAP 64u
|
||||
#define MAX_ASSIST_DEDUP 64u
|
||||
|
||||
@@ -87,7 +81,7 @@ static void credit_assist_to_mplayer(uint8_t *mp, uint8_t *victim)
|
||||
|
||||
if (mp == NULL || mp == victim_mp || !mark_assist_credited_once(victim, mp))
|
||||
return;
|
||||
pts = victim_mp ? SCORE_PVP_ASSIST : SCORE_AI_UNIT_ASSIST;
|
||||
pts = local_mp_event_score("assist", victim, victim_mp != NULL);
|
||||
local_mp_inc_mplayer_stat(mp, LMP_MP_OFF_ASSISTS);
|
||||
local_mp_add_mplayer_score(mp, pts, LMP_EXP_EVENT_ASSIST);
|
||||
local_mp_mark_mplayer_dirty(mp);
|
||||
@@ -144,8 +138,10 @@ static void __fastcall hook_dispatch_capture_zone(int64_t uid, uint8_t *capturer
|
||||
if (mp == NULL && capturer_unit != NULL)
|
||||
mp = *(uint8_t **)(capturer_unit + LMP_UNIT_OFF_MPLAYER);
|
||||
if (mp != NULL) {
|
||||
const uint8_t *own_unit = capturer_unit != NULL ? capturer_unit
|
||||
: (g_lmp_get_unit_by_eid ? (const uint8_t *)g_lmp_get_unit_by_eid(*(uint32_t *)(mp + LMP_MP_OFF_UNIT_EID)) : NULL);
|
||||
local_mp_inc_mplayer_stat(mp, LMP_MP_OFF_CAPTURE_ZONE);
|
||||
local_mp_add_mplayer_score(mp, SCORE_CAPTURE_ZONE, LMP_EXP_EVENT_CAPTURE_ZONE);
|
||||
local_mp_add_mplayer_score(mp, local_mp_event_score("capture", own_unit, 1), LMP_EXP_EVENT_CAPTURE_ZONE);
|
||||
local_mp_mark_mplayer_dirty(mp);
|
||||
if (local_mp_is_local_mplayer(mp)) {
|
||||
LocalMpAwardEvent award = { LMP_EXP_EVENT_CAPTURE_ZONE, NULL, 0, 0, NULL, 0 };
|
||||
@@ -163,7 +159,8 @@ static void __fastcall hook_dispatch_hit_crit(
|
||||
if (local_mp_is_host() && !is_kill && victim != NULL) {
|
||||
uint8_t *mp = local_mp_find_mplayer(uid, offender ? offender[LMP_OFFENDER_OFF_PID] : 0xffu);
|
||||
if (mp != NULL && mp != *(uint8_t **)(victim + LMP_UNIT_OFF_MPLAYER)) {
|
||||
float pts = is_crit ? SCORE_CRITICAL_HIT : SCORE_HIT;
|
||||
float pts = local_mp_event_score(is_crit ? "criticalHit" : "hit", victim,
|
||||
*(uint8_t **)(victim + LMP_UNIT_OFF_MPLAYER) != NULL);
|
||||
uint32_t ev = is_crit ? LMP_EXP_EVENT_CRITICAL_HIT : LMP_EXP_EVENT_HIT;
|
||||
local_mp_add_mplayer_score(mp, pts, ev);
|
||||
local_mp_mark_mplayer_dirty(mp);
|
||||
@@ -190,7 +187,7 @@ static void __fastcall hook_dispatch_severe_damage(int64_t uid, uint8_t *victim,
|
||||
int is_air = (utype == 0u || utype == 0xdu);
|
||||
if (is_air) local_mp_inc_mplayer_stat(mp, LMP_MP_OFF_AIR_SEVERE_DMG);
|
||||
else if (utype == 5u) local_mp_inc_mplayer_stat(mp, LMP_MP_OFF_SHIP_SEVERE_DMG);
|
||||
local_mp_add_mplayer_score(mp, SCORE_SEVERE_DAMAGE, LMP_EXP_EVENT_SEVERE_DAMAGE);
|
||||
local_mp_add_mplayer_score(mp, local_mp_event_score("severeDamage", victim, 1), LMP_EXP_EVENT_SEVERE_DAMAGE);
|
||||
local_mp_mark_mplayer_dirty(mp);
|
||||
if (local_mp_is_local_mplayer(mp)) {
|
||||
LocalMpAwardEvent award = { LMP_EXP_EVENT_SEVERE_DAMAGE, victim, 1, 0, NULL, 0 };
|
||||
@@ -210,7 +207,7 @@ static void __fastcall hook_dispatch_naval_damage(int64_t uid, uint8_t *victim,
|
||||
uint8_t *mp = local_mp_find_mplayer(uid, offender[LMP_OFFENDER_OFF_PID]);
|
||||
if (mp != NULL) {
|
||||
int32_t add_dmg = (int32_t)(award_dmg + 0.5f);
|
||||
float pts = award_dmg * SCORE_NAVAL_DMG_FACTOR;
|
||||
float pts = award_dmg * local_mp_score_param("wtoScore_damagePerPoint");
|
||||
if (add_dmg > 0) *(int32_t *)(mp + LMP_MP_OFF_AWARD_DAMAGE) += add_dmg;
|
||||
if (pts >= 1.0f) local_mp_add_mplayer_score(mp, pts, LMP_EXP_EVENT_UNIT_DAMAGE);
|
||||
local_mp_mark_mplayer_dirty(mp);
|
||||
|
||||
@@ -64,6 +64,10 @@ void local_mp_players_queue_spawn(int32_t slot_id, int32_t spare_type, int is_si
|
||||
void local_mp_report_award_event(const LocalMpAwardEvent *ev);
|
||||
const char *local_mp_unit_exp_class(const uint8_t *unit);
|
||||
|
||||
/* Mission scores of combat events from the mission settings (local_mp_scores.c). */
|
||||
float local_mp_score_param(const char *key);
|
||||
float local_mp_event_score(const char *event, const uint8_t *unit, int victim_is_player);
|
||||
|
||||
/* Assist deduplication lifecycle shared between kill and event hooks. */
|
||||
void local_mp_events_reset(void);
|
||||
void local_mp_events_begin_death(const uint8_t *victim);
|
||||
@@ -80,3 +84,4 @@ int install_local_mp_action_hooks(const uint8_t *text, size_t text_size);
|
||||
int install_local_mp_award_hooks(const uint8_t *text, size_t text_size, uint8_t *p_ground_dead);
|
||||
int install_local_mp_kill_hooks(const uint8_t *text, size_t text_size, uint8_t *p_ground_dead);
|
||||
int install_local_mp_event_hooks(const uint8_t *text, size_t text_size);
|
||||
int install_local_mp_score_reader(const uint8_t *text, size_t text_size);
|
||||
@@ -3,8 +3,9 @@
|
||||
*
|
||||
* Hooks BOTH `IGroundModel::onBecameDead` (tanks, IFVs, SPAA, boats, ships, infantry)
|
||||
* and `onUnitDeadOnce` (aircraft & helicopters). All 31 bound MPlayer bots receive 1:1
|
||||
* PvP kill/death counters and battle score alongside the local player. Kills made by the
|
||||
* local player are also reported as facts through local_mp_report_award_event().
|
||||
* PvP kill/death counters and battle score alongside the local player; the scores come from
|
||||
* the mission settings (local_mp_scores.c). Kills made by the local player are also reported
|
||||
* as facts through local_mp_report_award_event().
|
||||
*/
|
||||
#include "hooks.h"
|
||||
#include "hook_config.h"
|
||||
@@ -15,11 +16,6 @@
|
||||
|
||||
#include <string.h>
|
||||
|
||||
#define SCORE_PVP_KILL 200.0f
|
||||
#define SCORE_SEVERE_FINISH 40.0f
|
||||
#define SCORE_AI_UNIT_KILL 60.0f
|
||||
#define SCORE_DEATH 30.0f
|
||||
|
||||
typedef void (__fastcall *MPlayerAddScoreFn)(uint8_t *mp, float delta, uint32_t event_id, uint8_t add_team);
|
||||
typedef void (__fastcall *NetMarkDirtyFn)(void *dirty_field, void *owner_obj, void *payload_ptr);
|
||||
typedef void (__fastcall *ChooseOffenderVfn)(uint8_t *victim, uint8_t *out_offender, uint8_t clear_flag);
|
||||
@@ -80,7 +76,10 @@ static void record_enemy_kill(uint8_t *killer_mp, uint8_t *victim, int is_pvp)
|
||||
int is_human = (utype == 0xeu);
|
||||
int own_sev = is_pvp && (is_air || is_ship) && is_same_severe_offender(victim, killer_mp);
|
||||
uint32_t ev = is_air ? LMP_EXP_EVENT_KILL : (is_human ? LMP_EXP_EVENT_KILL_HUMAN : LMP_EXP_EVENT_KILL_GROUND);
|
||||
float pts = is_pvp ? (own_sev ? SCORE_SEVERE_FINISH : SCORE_PVP_KILL) : SCORE_AI_UNIT_KILL;
|
||||
/* Finishing a unit the killer had already severely damaged adds what the kill is worth over
|
||||
* the severe damage score the killer got then. */
|
||||
float pts = local_mp_event_score("kill", victim, is_pvp) -
|
||||
(own_sev ? local_mp_event_score("severeDamage", victim, is_pvp) : 0.0f);
|
||||
|
||||
if (is_pvp) {
|
||||
local_mp_inc_mplayer_stat(killer_mp, is_air ? LMP_MP_OFF_KILLS : (is_ship ? LMP_MP_OFF_NAVAL_KILLS :
|
||||
@@ -123,7 +122,6 @@ static void process_unit_death(uint8_t *victim, uint8_t *killer_mp, int32_t kill
|
||||
|
||||
if (victim_mp != NULL) {
|
||||
local_mp_inc_mplayer_stat(victim_mp, LMP_MP_OFF_DEATHS);
|
||||
local_mp_add_mplayer_score(victim_mp, SCORE_DEATH, LMP_EXP_EVENT_DEATH);
|
||||
local_mp_mark_mplayer_dirty(victim_mp);
|
||||
}
|
||||
if (!allow_kill_credit || killer_mp == NULL || killer_mp == victim_mp)
|
||||
@@ -177,13 +175,6 @@ static void __fastcall hook_iground_on_became_dead(uint8_t *victim, int32_t p2)
|
||||
}
|
||||
process_unit_death(victim, killer_mp, killer_army, allow_kill);
|
||||
}
|
||||
if (is_host && *g_local_mp_multiplayer != NULL) {
|
||||
(*g_local_mp_multiplayer)[LMP_MP_MGR_OFF_IS_LOCAL_MP] = 0;
|
||||
orig_iground_on_dead(victim, p2);
|
||||
if (*g_local_mp_multiplayer != NULL)
|
||||
(*g_local_mp_multiplayer)[LMP_MP_MGR_OFF_IS_LOCAL_MP] = 1;
|
||||
return;
|
||||
}
|
||||
orig_iground_on_dead(victim, p2);
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,6 @@
|
||||
#define LMP_EXP_EVENT_CRITICAL_HIT 10u
|
||||
#define LMP_EXP_EVENT_HIT 13u
|
||||
#define LMP_EXP_EVENT_UNIT_DAMAGE 24u
|
||||
#define LMP_EXP_EVENT_DEATH 30u
|
||||
#define LMP_EXP_EVENT_SEVERE_DAMAGE 35u
|
||||
#define LMP_EXP_EVENT_KILL_HUMAN 39u
|
||||
#define LMP_EXP_EVENT_COUNT 45u
|
||||
@@ -55,6 +54,9 @@
|
||||
#define LMP_MIS_OFF_ALLIES_COUNTRY 0x00d0u
|
||||
#define LMP_MIS_OFF_ARCADE_COUNTRY 0x01d0u
|
||||
#define LMP_MIS_OFF_CUSTOM_BOTS 0x0718u
|
||||
/* MissionSettings copy of the mission block customScoreParams (2.61.0.37 loader 0x12657a0 copies it at
|
||||
* 0x126d762); the client never reads it, local_mp_scores.c reads the local service's score table there. */
|
||||
#define LMP_MIS_OFF_CUSTOM_SCORE_PARAMS 0x06d8u
|
||||
#define LMP_MATCH_INFO_OFF_TEAM 0x0004u
|
||||
|
||||
/*
|
||||
@@ -93,8 +95,6 @@
|
||||
#define LMP_MP_OFF_USED_SPARES_MASK 0x0520u
|
||||
#define LMP_MP_OFF_GUI_STATE 0x0640u
|
||||
#define LMP_MP_OFF_UNIT_EID 0x0850u
|
||||
#define LMP_MP_OFF_SUPPORT_UNIT_EID 0x0880u
|
||||
#define LMP_MP_FLAG_SPECTATOR_MASK 0x00020020u
|
||||
#define LMP_MP_OFF_SCORE 0x08f8u
|
||||
#define LMP_MP_OFF_KILLS 0x09d8u
|
||||
#define LMP_MP_OFF_TEAM_KILLS 0x09dau
|
||||
@@ -124,16 +124,16 @@
|
||||
* @anchor "setMyPlayer uid:%i eid:%08x ptr:%p pid:%d (saved pid:%d)"
|
||||
* @anchor "IGroundModel__onBecameDead"
|
||||
*/
|
||||
#define LMP_UNIT_OFF_ALIVE_STATE 0x0088u
|
||||
#define LMP_UNIT_OFF_TYPE 0x008cu
|
||||
#define LMP_UNIT_OFF_DEAD_FLAGS 0x0090u
|
||||
#define LMP_UNIT_OFF_SEVERE_IDX 0x06b0u
|
||||
#define LMP_UNIT_OFF_SEVERE_PID 0x06d0u
|
||||
#define LMP_UNIT_OFF_SEVERE_UID 0x0708u
|
||||
#define LMP_UNIT_OFF_BAIL_STATE 0x0f90u
|
||||
#define LMP_UNIT_OFF_MPLAYER 0x0f98u
|
||||
#define LMP_UNIT_DEAD_FLAGS_MASK 0x01000014u
|
||||
/* Unit type at +0x8c (the stock scoreboard counters split kills by it, see local_mp_kills.c). */
|
||||
#define LMP_UNIT_TYPE_AIRCRAFT 0x0000u
|
||||
#define LMP_UNIT_TYPE_SHIP 0x0005u
|
||||
#define LMP_UNIT_TYPE_HELICOPTER 0x000du
|
||||
#define LMP_UNIT_TYPE_HUMAN 0x000eu
|
||||
#define LMP_UNIT_OFF_ARMY 0x1010u
|
||||
#define LMP_UNIT_OFF_PID 0x1018u
|
||||
#define LMP_UNIT_OFF_INFO 0x1020u
|
||||
@@ -242,6 +242,9 @@
|
||||
#define LMP_SIG_DATABLOCK_SET_FROM "41 57 41 56 41 55 41 54 56 57 55 53 48 83 ec 48 48 89 d7 48 89 ce 66 2e 0f 1f 84 00 00 00 00 00 b9 90 00 00 00 e8 ?? ?? ?? ?? 48 85 c0 75 ?? 48 8b 05 ?? ?? ?? ??"
|
||||
#define LMP_SIG_DATABLOCK_DTOR "41 57 41 56 41 54 56 57 53 48 83 ec 38 0f 29 74 24 20 48 8b 41 18"
|
||||
#define LMP_SIG_DATABLOCK_GET_STR "48 83 ec 28 4c 89 44 24 20 4c 8d 44 24 20 e8 ?? ?? ?? ?? 90 48 83 c4 28 c3 cc cc cc cc cc cc cc 41 57"
|
||||
/* float getReal(const DataBlock *, const char *name, float def): 2.61.0.37 wrapper 0x5445270 around
|
||||
* DataBlock::getReal 0x30961a0 (the call MPlayer::addScore 0x59f2d0 uses for spawnScoreMultiplier). */
|
||||
#define LMP_SIG_DATABLOCK_GET_REAL "48 83 ec 28 f3 0f 11 54 24 24 4c 8d 44 24 24 e8 ?? ?? ?? ?? 90 48 83 c4 28 c3 cc cc cc cc cc cc 56 57 53 48 83 ec 30 48 89 d7 48 89 ce 48 8d 15"
|
||||
#define LMP_SIG_MP_CONSTRUCT_LOCAL "56 57 53 48 83 ec 60 48 89 ce 48 81 c1 f8 00 00 00 e8 ?? ?? ?? ?? 66 c7 46 60 01 01"
|
||||
#define LMP_SIG_MP_INIT_CHAT "41 57 41 56 41 54 56 57 53 48 83 ec 48 48 89 d7 48 89 ce 48 8b 05 ?? ?? ?? ?? 48 85 c0 74 ?? c6 00 01 48 8b 9e 00 02 00 00"
|
||||
#define LMP_SIG_IGROUND_AWARD_ASSISTS "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec a8 01 00 00 44 0f 29 94 24 90 01 00 00 44 0f 29 8c 24 80 01 00 00 44 0f 29 84 24 70 01 00 00 0f 29 bc 24 60 01 00 00 0f 29 b4 24 50 01 00 00 48 89 ce 48 8b 01 48 8d 54 24 28 41 b0 01 ff 90 98 04 00 00"
|
||||
@@ -254,7 +257,6 @@
|
||||
#define LMP_SIG_STR_HASH_FNV1 "41 56 56 57 53 49 89 d0 49 ba db 28 b4 a0 d1 7e 03 e7 48 83 fa 10 77 76"
|
||||
#define LMP_SIG_NAMEMAP_ADD_NAME_ID "41 57 41 56 41 55 41 54 56 57 55 53 48 83 ec 38 44 89 cf 48 89 ce 80 79 4b 00"
|
||||
#define LMP_SIG_CREW_SKILLS_INIT "41 56 56 57 55 53 48 81 ec 90 00 00 00 0f 29 b4 24 80 00 00 00 0f 28 f3"
|
||||
#define LMP_SIG_UCAV_LAUNCH "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 18 02 00 00 0f 29 bc 24 00 02 00 00 0f 29 b4 24 f0 01 00 00 48 8b 05 ?? ?? ?? ??"
|
||||
#define LMP_SIG_IGROUND_ON_DEAD "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec a8 01 00 00 44 0f 29 8c 24 90 01 00 00 44 0f 29 84 24 80 01 00 00 0f 29 bc 24 70 01 00 00 0f 29 b4 24 60 01 00 00 89 d3"
|
||||
#define LMP_SIG_ON_UNIT_DEAD_ONCE "41 57 41 56 41 55 41 54 56 57 55 53 48 81 ec 98 01 00 00 44 0f 29 84 24 80 01 00 00 0f 29 bc 24 70 01 00 00 0f 29 b4 24 60 01 00 00 80 b9 58 30 00 00 00 0f 85 ?? ?? ?? ?? 48 89 ce 48 8d 54 24 38 e8 ?? ?? ?? ?? 66 83 7c 24 38 ff"
|
||||
#define LMP_SIG_MPLAYER_ADD_SCORE "41 57 41 56 56 57 55 53 48 81 ec 88 00 00 00 0f 29 7c 24 70 0f 29 74 24 60 48 89 ce 44 89 c0 f3 0f 2a 84 81 fc 08 00 00 0f 28 f9 f3 0f 58 c1 f3 0f 2c c8 89 8c 86 fc 08 00 00"
|
||||
@@ -265,5 +267,4 @@
|
||||
#define LMP_SIG_CALLER_HIT_CRIT "8b 0d ?? ?? ?? ?? f7 c1 00 00 08 00 75 ?? f7 c1 00 00 00 01 75 ?? 0f b6 8f 10 10 00 00 39 4e 1c 74 ?? 41 20 c0 0f b6 86 49 01 00 00 0f 57 db f3 0f 5f 9e 30 01 00 00 48 8b 4e 58 85 ed f3 0f 5d 1d ?? ?? ?? ?? 88 44 24 30 0f 9f 44 24 28 44 88 44 24 20 48 89 fa 49 89 f0 e8 ?? ?? ?? ??"
|
||||
#define LMP_SIG_CALLER_SEVERE_DMG "66 83 be b0 06 00 00 ff 0f 85 ?? ?? ?? ?? 48 89 f1 e8 ?? ?? ?? ?? 84 c0 0f 84 ?? ?? ?? ?? 48 8d 9e b0 06 00 00 48 8b 4f 58 48 89 f2 49 89 f8 e8 ?? ?? ?? ?? 48 89 f1 48 89 fa e8 ?? ?? ?? ?? 0f b6 ae d4 06 00 00"
|
||||
#define LMP_SIG_CALLER_NAVAL_DMG "66 83 b9 90 0f 00 00 01 77 ?? 66 83 ff ff 74 ?? 0f b7 c7 0f 57 d2 f3 0f 2a d0 f3 0f 59 15 ?? ?? ?? ?? eb ?? f3 0f 10 15 ?? ?? ?? ?? 48 8b 94 24 c0 03 00 00 0f b6 7c 24 5b 41 89 f9 e8 ?? ?? ?? ?? 0f 57 c0 0f 2e f0 0f 96 c0 40 08 f8 a8 01 75 ?? 48 8b 96 e8 0a 00 00 4c 8b 84 24 c0 03 00 00 49 8b 48 58 0f 28 de e8 ?? ?? ?? ??"
|
||||
#define LMP_SIG_COUNT_ACTIVE_PLAYERS "41 57 41 56 41 54 56 57 53 48 83 ec 38 89 cf 80 f2 01 0f b6 c2 c1 e0 0a 83 c8 3a"
|
||||
#define LMP_SIG_IS_SLOT_READY_AT_HOST "41 56 56 57 55 53 48 81 ec a0 00 00 00 0f 29 b4 24 90 00 00 00 44 89 c3 48 89 d6 48 83 3d"
|
||||
@@ -0,0 +1,63 @@
|
||||
/*
|
||||
* Mission scores of combat events on the LocalMP scoreboard, read from the mission settings.
|
||||
*
|
||||
* Online the battle server scores every event. The local service writes the official mission
|
||||
* scores (tuning/battle-economy.jsonc, BattleEconomy.missionScores) into the mission settings
|
||||
* block `customScoreParams`, which the 2.61.0.37 client copies into MissionSettings+0x6d8
|
||||
* (0x126d762 in the mission settings loader 0x12657a0) and never reads itself. Keys:
|
||||
* wtoScore_<event>_<group> event: kill, assist, severeDamage, criticalHit, hit, capture
|
||||
* group: ground, air, naval, human (the victim's; the capturer's own
|
||||
* for capture)
|
||||
* wtoScore_damagePerPoint naval award damage
|
||||
* wtoScore_aiMul victims that are not players (warpoints.blk aiKillK)
|
||||
* A missing key scores 0, so nothing here carries a score of its own.
|
||||
*/
|
||||
#include "hooks.h"
|
||||
#include "local_mp_internal.h"
|
||||
#include "local_mp_offsets.h"
|
||||
|
||||
#include <stdio.h>
|
||||
|
||||
typedef float (__fastcall *DataBlockGetRealFn)(const void *blk, const char *name, float def);
|
||||
|
||||
static DataBlockGetRealFn fn_datablock_get_real;
|
||||
|
||||
static const char *unit_score_group(const uint8_t *unit)
|
||||
{
|
||||
uint16_t type;
|
||||
|
||||
if (unit == NULL)
|
||||
return "ground";
|
||||
type = *(const uint16_t *)(unit + LMP_UNIT_OFF_TYPE);
|
||||
if (type == LMP_UNIT_TYPE_AIRCRAFT || type == LMP_UNIT_TYPE_HELICOPTER)
|
||||
return "air";
|
||||
if (type == LMP_UNIT_TYPE_SHIP)
|
||||
return "naval";
|
||||
if (type == LMP_UNIT_TYPE_HUMAN)
|
||||
return "human";
|
||||
return "ground";
|
||||
}
|
||||
|
||||
float local_mp_score_param(const char *key)
|
||||
{
|
||||
if (fn_datablock_get_real == NULL || g_local_mp_mission_settings == NULL || key == NULL)
|
||||
return 0.0f;
|
||||
return fn_datablock_get_real(g_local_mp_mission_settings + LMP_MIS_OFF_CUSTOM_SCORE_PARAMS, key, 0.0f);
|
||||
}
|
||||
|
||||
float local_mp_event_score(const char *event, const uint8_t *unit, int victim_is_player)
|
||||
{
|
||||
char key[64];
|
||||
float score;
|
||||
|
||||
snprintf(key, sizeof(key), "wtoScore_%s_%s", event, unit_score_group(unit));
|
||||
score = local_mp_score_param(key);
|
||||
return victim_is_player ? score : score * local_mp_score_param("wtoScore_aiMul");
|
||||
}
|
||||
|
||||
int install_local_mp_score_reader(const uint8_t *text, size_t text_size)
|
||||
{
|
||||
fn_datablock_get_real = (DataBlockGetRealFn)local_mp_scan_unique(
|
||||
text, text_size, "DataBlock::getReal", LMP_SIG_DATABLOCK_GET_REAL);
|
||||
return fn_datablock_get_real != NULL;
|
||||
}
|
||||
@@ -11,7 +11,7 @@
|
||||
*/
|
||||
import type { BattleEconomyData, EconomyDifficulty, VehicleEconomy } from '../game-data/datasets/battle-economy.ts';
|
||||
import type { ModeDifficulty } from '../game-modes/catalogue/game-mode-declaration.ts';
|
||||
import type { BattleEconomyTuning, ScoredEvent, VictimGroup } from './battle-economy-tuning.ts';
|
||||
import { SCORED_EVENTS, VICTIM_GROUPS, type BattleEconomyTuning, type ScoredEvent, type VictimGroup } from './battle-economy-tuning.ts';
|
||||
|
||||
/** EXP_EVENT_* codes the LocalMP host reports (gui.vromfs.bin globalScripts/expEventConsts.nut). */
|
||||
export const ExpEvent = {
|
||||
@@ -177,6 +177,23 @@ export class BattleEconomy {
|
||||
};
|
||||
}
|
||||
|
||||
/**
|
||||
* The scoreboard score of each combat event, for the mission settings block customScoreParams
|
||||
* that the native LocalMP bridge reads (native/wto-net/src/local_mp_scores.c lists the keys):
|
||||
* the official mission scores of tuning/battle-economy.jsonc, and aiKillK for victims that are
|
||||
* not players, as in the rewards.
|
||||
*/
|
||||
missionScores(): Readonly<Record<string, number>> {
|
||||
const scores: Record<string, number> = {};
|
||||
for (const group of VICTIM_GROUPS) {
|
||||
for (const event of SCORED_EVENTS) scores[`wtoScore_${event}_${group}`] = this.#tuning.eventScores[group][event];
|
||||
scores[`wtoScore_capture_${group}`] = this.#tuning.captureZoneScore[group];
|
||||
}
|
||||
scores.wtoScore_damagePerPoint = this.#tuning.navalDamageScorePerPoint;
|
||||
scores.wtoScore_aiMul = this.data.aiKillK;
|
||||
return scores;
|
||||
}
|
||||
|
||||
#score(code: number, group: VictimGroup): number | undefined {
|
||||
const scored = (event: ScoredEvent): number => this.#tuning.eventScores[group][event];
|
||||
switch (code) {
|
||||
|
||||
@@ -30,7 +30,12 @@ const VERSUS_SWITCHES: readonly string[] = [
|
||||
'allowSpare', 'isLimitedAmmo', 'allowUseArtillerySupport', 'isBotsAllowed', 'autoBalance',
|
||||
];
|
||||
|
||||
export function battleMissionSettings(plan: BattleLaunchPlan): BlkBlock {
|
||||
/**
|
||||
* `scores`: the scoreboard score table (BattleEconomy.missionScores) for the native LocalMP bridge,
|
||||
* written into the stock mission block customScoreParams, which the client copies into its
|
||||
* MissionSettings without reading it (native/wto-net/src/local_mp_scores.c).
|
||||
*/
|
||||
export function battleMissionSettings(plan: BattleLaunchPlan, scores: Readonly<Record<string, number>>): BlkBlock {
|
||||
const settings = emptyBlock();
|
||||
copyMissionParams(settings, plan);
|
||||
if (plan.level !== undefined) setParam(settings, 'level', text(plan.level));
|
||||
@@ -57,6 +62,8 @@ export function battleMissionSettings(plan: BattleLaunchPlan): BlkBlock {
|
||||
setParam(settings, 'maxBots', integer(plan.maxBots));
|
||||
|
||||
addPersistentSpawnCosts(settings, plan.extraBattleSlots);
|
||||
const scoreParams = ensureBlock(settings, 'customScoreParams');
|
||||
for (const [name, value] of Object.entries(scores)) setParam(scoreParams, name, real(value));
|
||||
for (const name of ['ranks', 'forcedRanks']) {
|
||||
const ranks = ensureBlock(settings, name);
|
||||
setParam(ranks, 'min', integer(plan.minMrank));
|
||||
@@ -129,3 +136,7 @@ function integer(value: number): BlkValue {
|
||||
function flag(value: boolean): BlkValue {
|
||||
return { type: 'bool', value };
|
||||
}
|
||||
|
||||
function real(value: number): BlkValue {
|
||||
return { type: 'real', value };
|
||||
}
|
||||
@@ -32,11 +32,15 @@ export interface BattleLaunchNotify extends Record<string, unknown> {
|
||||
readonly battle: Readonly<Record<string, unknown>>;
|
||||
}
|
||||
|
||||
export function battleLaunchNotify(plan: BattleLaunchPlan, awards: BannerParams): BattleLaunchNotify {
|
||||
export function battleLaunchNotify(
|
||||
plan: BattleLaunchPlan,
|
||||
awards: BannerParams,
|
||||
scores: Readonly<Record<string, number>>,
|
||||
): BattleLaunchNotify {
|
||||
return {
|
||||
from: 'wto_battle',
|
||||
func: 'launch',
|
||||
mission: toWire(battleMissionSettings(plan)),
|
||||
mission: toWire(battleMissionSettings(plan, scores)),
|
||||
lobby: {
|
||||
game_mode_id: plan.modeId,
|
||||
game_mode_name: plan.modeName,
|
||||
|
||||
@@ -110,7 +110,7 @@ function handleEnqueue(
|
||||
setImmediate(() => {
|
||||
if (!deps.sessions.isPending(userId, launch.sessionId)) return;
|
||||
deps.sessions.clearPending(userId, launch.sessionId);
|
||||
deps.notifyLaunch(userId, battleLaunchNotify(launch, awards));
|
||||
deps.notifyLaunch(userId, battleLaunchNotify(launch, awards, deps.economy.missionScores()));
|
||||
});
|
||||
return {};
|
||||
}
|
||||
|
||||
@@ -9,6 +9,9 @@
|
||||
// x eventScore / referenceScore(victim group)
|
||||
// Research Points = eventScore x expMul(own vehicle) x RP class factor(victim)
|
||||
// both x aiKillK when the victim is not a player.
|
||||
// The same mission scores (x aiKillK for non-player victims) are the scoreboard score: they go to
|
||||
// the client in the mission settings block customScoreParams (BattleEconomy.missionScores) and the
|
||||
// native LocalMP bridge adds them on the scoreboard.
|
||||
{
|
||||
// Destroyed-unit classes (warpoints.blk / rank.blk units{} keys) by victim group; any class not
|
||||
// listed counts as "ground".
|
||||
|
||||
Reference in new issue
Block a user