From 646be7afb9a4c6b4961a743bd41e13ede2fa3b32 Mon Sep 17 00:00:00 2001 From: N0VAN0M4LY <224130499+N0VAN0M4LY@users.noreply.github.com> Date: Wed, 2 Dec 2026 21:33:46 +0800 Subject: [PATCH] fix(battle): load player crew skills on LocalMP host Unit::loadCrew previously skipped reading the player's equipped crew from the profile whenever Multiplayer+0x60 (host flag) was non-zero, leaving human players with default skills and no Expert/Ace bonuses. Calling UnitCrewSkills::initFromSave after Unit::changeAircraft in the native loadout hook ran too late to affect live vehicle crew state. Add exe patch battle/load-local-host-player-crew to check both the host and LocalMP flags (+0x60 and +0x61) in Unit::loadCrew so only non-LocalMP hosts skip directly to the default crew while preserving the owner check. Remove the late initFromSave workaround from local_mp_loadout.c (keeping its native patch sites for compatibility with 0.1.2 hook DLLs) and add the E-Crew skills in battle feature labels to the launcher locales. Verified with check-patches on 2.61.0.37 (0x10025dd) and 2.61.0.58 (0x100700d), native wto_ws.dll build, launcher typecheck and build; pending in-game verification. --- .../src/renderer/src/i18n/locales/en.json | 1 + .../src/renderer/src/i18n/locales/zh-CN.json | 1 + native/wto-net/src/local_mp_loadout.c | 11 +---- native/wto-net/src/local_mp_offsets.h | 1 - native/wto-net/src/local_mp_values.c | 2 - native/wto-net/src/local_mp_values.h | 3 +- .../load-local-host-player-crew/patch.jsonc | 43 +++++++++++++++++++ patches/native/local_mp_loadout.jsonc | 3 +- 8 files changed, 50 insertions(+), 15 deletions(-) create mode 100644 patches/exe/battle/load-local-host-player-crew/patch.jsonc diff --git a/apps/launcher/src/renderer/src/i18n/locales/en.json b/apps/launcher/src/renderer/src/i18n/locales/en.json index 93f5234..af4fe17 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/en.json +++ b/apps/launcher/src/renderer/src/i18n/locales/en.json @@ -666,6 +666,7 @@ "J-Ground arcade and realistic": "Ground battles (arcade, realistic)", "J-Air arcade and realistic": "Air battles (arcade, realistic)", "J-Naval arcade and realistic": "Naval battles (arcade, realistic)", + "E-Crew skills in battle": "Crew skills and qualifications in battle", "J-Sub-modes": "Additional modes (such as night battles)", "K-AI opponents and teammates": "AI opponents and allies", "K-Spawn score and respawns": "Spawn points and respawning", diff --git a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json index 8caa118..40e6b22 100644 --- a/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json +++ b/apps/launcher/src/renderer/src/i18n/locales/zh-CN.json @@ -666,6 +666,7 @@ "J-Ground arcade and realistic": "陆战(街机、历史)", "J-Air arcade and realistic": "空战(街机、历史)", "J-Naval arcade and realistic": "海战(街机、历史)", + "E-Crew skills in battle": "战局乘员技能与资格", "J-Sub-modes": "附加模式(如夜战)", "K-AI opponents and teammates": "AI 对手与队友", "K-Spawn score and respawns": "出生点数与重生", diff --git a/native/wto-net/src/local_mp_loadout.c b/native/wto-net/src/local_mp_loadout.c index 57ca073..2eaca0b 100644 --- a/native/wto-net/src/local_mp_loadout.c +++ b/native/wto-net/src/local_mp_loadout.c @@ -1,10 +1,10 @@ /* - * LocalMP vehicle loadout, modification map, decals, 3D attachables, and crew-skill bridge. + * LocalMP vehicle loadout, modification map, decals, and 3D attachables. * * The 2.61.0.37 client has no receiver for its own vehicle change request (0xb01d, * SemChangeAircraftRequest) on a host; hook_sem_change_aircraft_send builds the * ChangeUnitReflection from the request (weapon, modifications, bullets, skin, decals, - * attachables, crew skills, spawn base) and calls Unit::changeAircraft itself. + * attachables, spawn base) and calls Unit::changeAircraft itself. */ #include "hooks.h" #include "hook_config.h" @@ -37,7 +37,6 @@ typedef const void *(__fastcall *GetAttachablesBlkFn)( ); typedef uint64_t (__fastcall *StrHashFnv1Fn)(const char *str, size_t len); typedef int32_t (__fastcall *NameMapAddNameIdFn)(void *map, const char *str, size_t len, uint64_t hash); -typedef void (__fastcall *CrewSkillsInitFn)(void *crew_skills, void *econ_state, const char *unit_name, float mult); static SemChangeAircraftSendFn orig_sem_send; static ReflCtorFn fn_refl_ctor; @@ -50,7 +49,6 @@ static GetDecalsBlkFn fn_get_decals_blk; static GetAttachablesBlkFn fn_get_attachables_blk; static StrHashFnv1Fn fn_str_hash; static NameMapAddNameIdFn fn_namemap_add; -static CrewSkillsInitFn fn_crew_skills_init; static void populate_namemap_csv(void *map, const char *csv) { @@ -133,7 +131,6 @@ static void __fastcall hook_sem_change_aircraft_send( { uint8_t *hero, *mplayer, *econ_state, *req; const void *bullets_begin, *bullets_end; - void *crew_skills; int32_t req_slot_id, req_base_id, req_spare_type; int is_silent; __declspec(align(16)) uint8_t refl[LMP_REFL_SIZE]; @@ -188,9 +185,6 @@ static void __fastcall hook_sem_change_aircraft_send( fn_unit_change_aircraft(hero, refl, 1); fn_refl_dtor(refl); - crew_skills = *(void **)(hero + LMP_UNIT_OFF_CREW_SKILLS); - if (crew_skills != NULL && unit_name != NULL && unit_name[0] != '\0') - fn_crew_skills_init(crew_skills, econ_state, unit_name, 1.0f); if (mplayer[LMP_MP_OFF_GUI_STATE] != LMP_GUI_STATE_PILOT_CONTROL && mplayer[LMP_MP_OFF_GUI_STATE] != LMP_GUI_STATE_CA_READY) g_lmp_set_player_gui_state((int32_t)mplayer[LMP_MP_OFF_PID], LMP_GUI_STATE_CA_READY); @@ -222,7 +216,6 @@ int install_local_mp_loadout_hooks(void) fn_get_attachables_blk = (GetAttachablesBlkFn)g_lmp.get_attachables_blk; fn_str_hash = (StrHashFnv1Fn)g_lmp.str_hash_fnv1; fn_namemap_add = (NameMapAddNameIdFn)g_lmp.namemap_add_name_id; - fn_crew_skills_init = (CrewSkillsInitFn)g_lmp.crew_skills_init; return local_mp_queue_hooks("local_mp_loadout", hooks, sizeof(hooks) / sizeof(hooks[0])); } diff --git a/native/wto-net/src/local_mp_offsets.h b/native/wto-net/src/local_mp_offsets.h index 115b0b7..acf0562 100644 --- a/native/wto-net/src/local_mp_offsets.h +++ b/native/wto-net/src/local_mp_offsets.h @@ -125,7 +125,6 @@ #define LMP_UNIT_OFF_INFO (g_lmp.unit_info) #define LMP_UNIT_INFO_OFF_NAME (g_lmp.unit_info_name) #define LMP_UNIT_INFO_OFF_EXP_CLASS (g_lmp.unit_info_exp_class) -#define LMP_UNIT_OFF_CREW_SKILLS (g_lmp.unit_crew_skills) #define LMP_UNIT_VTF_CHOOSE_OFFENDER (g_lmp.unit_vtf_choose_offender) #define LMP_UNIT_OFF_SKIP_KILL (g_lmp.unit_skip_kill) #define LMP_IGM_OFF_OFFENDERS_PTR (g_lmp.igm_offenders) diff --git a/native/wto-net/src/local_mp_values.c b/native/wto-net/src/local_mp_values.c index 357edc6..60a400c 100644 --- a/native/wto-net/src/local_mp_values.c +++ b/native/wto-net/src/local_mp_values.c @@ -76,7 +76,6 @@ static const LmpValueSpec SPECS[] = { 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), - A(LOADOUT, "crew_skills_init", crew_skills_init), 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), @@ -91,7 +90,6 @@ static const LmpValueSpec SPECS[] = { 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), - O(LOADOUT, "unit_crew_skills.crew_skills", unit_crew_skills), 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), diff --git a/native/wto-net/src/local_mp_values.h b/native/wto-net/src/local_mp_values.h index ca4d6ea..378deb1 100644 --- a/native/wto-net/src/local_mp_values.h +++ b/native/wto-net/src/local_mp_values.h @@ -29,7 +29,7 @@ typedef struct LmpValues { /* local_mp_loadout */ uint8_t *sem_change_aircraft_send, *refl_ctor, *datablock_dtor, *bullet_vec_assign, *get_decals_blk; - uint8_t *get_attachables_blk, *str_hash_fnv1, *namemap_add_name_id, *crew_skills_init; + uint8_t *get_attachables_blk, *str_hash_fnv1, *namemap_add_name_id; size_t refl_bullets, refl_disabled_mods, refl_enabled_mods, refl_custom_preset, refl_attachables, refl_decals; size_t refl_custom_skin, refl_skin, refl_weapon, refl_unit, refl_flags, refl_gun_convergence; size_t refl_vertical_targeting, refl_bomb_fuse, refl_fuel; @@ -37,7 +37,6 @@ typedef struct LmpValues { /* Change request members: captured as offsets in the economic state, used relative to the request. */ size_t econ_req_slot_id, econ_req_bullets_begin, econ_req_bullets_end; size_t req_slot_id, req_bullets_begin, req_bullets_end; - size_t unit_crew_skills; /* local_mp_actions */ uint8_t *mp_init_chat; diff --git a/patches/exe/battle/load-local-host-player-crew/patch.jsonc b/patches/exe/battle/load-local-host-player-crew/patch.jsonc new file mode 100644 index 0000000..bef9fb3 --- /dev/null +++ b/patches/exe/battle/load-local-host-player-crew/patch.jsonc @@ -0,0 +1,43 @@ +// Let Unit::loadCrew read the local player's equipped crew when the multiplayer host is LocalMP. +// Why the exe: native initialization skips the profile on hosts before it builds the live crew object. +// Without it: a human player's LocalMP unit receives default skills instead of the crew in the profile. +{ + "id": "battle/load-local-host-player-crew", + "title": "Load the equipped player's crew on a LocalMP host", + "features": ["E-Crew skills in battle"], + "requires": [], + "variants": [ + // Unit::loadCrew tests the host flag, then the unit's player bit and the local player ID. + // The adjacent host and LocalMP fields are boolean bytes at +0x60 and +0x61 in Multiplayer. + // Keep the owner checks and skip to the default crew only for a non-LocalMP host. + // 2.61.0.37: site 0x10025d6, edit at 0x10025dd; 2.61.0.58: edit at 0x100700d. + { + "written_for": "2.61.0.37", + "locate": { + "method": "signature", + "section": ".text", + "pattern": "48 8b 05 ?? ?? ?? ?? 48 85 c0 74 0a 80 78 60 00 0f 85 ?? ?? ?? ?? 8b 86 90 00 00 00 a9 00 01 00 00 75 15 48 8b 05 ?? ?? ?? ?? 8b 80 a4 05 00 00 39 c5", + "captures": { + "default_crew": { "offset": 18, "type": "rel32" } + } + }, + "edit": { + "offset": 7, + "asm": [ + "test rax, rax", + "je check_owner", + "cmp word ptr [rax + 0x60], 1", + "je {default_crew}", + "check_owner:", + "test byte ptr [rsi + 0x91], 1", + "nop", + "nop", + "nop" + ], + "bytes": "48 85 c0 74 0b 66 83 78 60 01 0f 84 ?? ?? ?? ?? f6 86 91 00 00 00 01 90 90 90", + "expect_original": "48 85 c0 74 0a 80 78 60 00 0f 85 ?? ?? ?? ?? 8b 86 90 00 00 00 a9 00 01 00 00", + "fixups": [{ "at": 12, "type": "rel32", "target": "default_crew" }] + } + } + ] +} diff --git a/patches/native/local_mp_loadout.jsonc b/patches/native/local_mp_loadout.jsonc index f55158b..08c762e 100644 --- a/patches/native/local_mp_loadout.jsonc +++ b/patches/native/local_mp_loadout.jsonc @@ -117,7 +117,7 @@ } ] }, - // UnitCrewSkills::initFromSave. + // UnitCrewSkills::initFromSave, required by hook DLLs bundled in 0.1.2. // 2.61.0.37: 0x1032130 "crew_skills_init": { "variants": [ @@ -408,6 +408,7 @@ }, // A Unit method that starts by reading the unit crew skills. // 2.61.0.37: 0x485850 (push r15; push r14; push r12; ...) + // Also required by the 0.1.2 hook DLLs. "unit_crew_skills": { "variants": [ {