fix(battle): unblock LocalMP backup respawns and normalize unit names
Store the selected LocalMP backup token in a separate wtoLastBackup handler field instead of mutating requestData.wtoBackup. Mutating requestData caused respawn.nut checkReady() u.isEqual(lastRequestData, getSelectedRequestData()) to always evaluate false for backup spawns, preventing doRespawnPlayer() from ever running. Also fix downstream ground and naval backup accounting where native UnitInfo::name carries folder prefixes (e.g. tankModels/cn_type_59) that mismatched bare unit IDs in session.spareSlots, by stripping path prefixes in local_mp_awards.c, record-local-battle-awards, battle-spares.ts, and battle-queue-requests.ts. Update hook_is_slot_ready_at_host to check USED_SPARES_MASK rather than BROKEN_SLOTS_MASK so unrepaired slots remain eligible for a backup spawn. Verified root and launcher typecheck, 2.61.0.37 and 2.61.0.58 check-gui (50 patches / 37 .nut), check-patches (14/14), checkPatchSet, battle-spares runnable check, and MSVC temp build of wto_ws.dll (0 warnings in project C sources). Pending regular-terminal build of build/native/wto_ws.dll and in-game acceptance.
This commit is contained in:
1 parent
c3cf4e3707
commit
647eff35fe
11 files changed
+49
-16
No files matched your search
@@ -16,12 +16,19 @@ export interface BackupSpawn {
|
||||
readonly backup: string;
|
||||
}
|
||||
|
||||
/** Strip native model folder prefixes (e.g. "tankModels/cn_type_59" -> "cn_type_59"). */
|
||||
export function normalizeBackupUnitName(unit: string): string {
|
||||
const slash = unit.lastIndexOf('/');
|
||||
return slash >= 0 ? unit.slice(slash + 1) : unit;
|
||||
}
|
||||
|
||||
function receiptKey(session: BattleSession, slot: number): string {
|
||||
return `${session.sessionId}_${slot}`;
|
||||
}
|
||||
|
||||
export function recordDailyBackupSpawn(profile: BlkBlock, session: BattleSession, spawn: BackupSpawn): boolean {
|
||||
return spawn.backup === DAILY_BACKUP && session.spareSlots?.get(spawn.slot) === spawn.unit
|
||||
const unit = normalizeBackupUnitName(spawn.unit);
|
||||
return spawn.backup === DAILY_BACKUP && session.spareSlots?.get(spawn.slot) === unit
|
||||
&& recordDailySpare(profile, session.startedAtSec, receiptKey(session, spawn.slot));
|
||||
}
|
||||
|
||||
@@ -32,11 +39,12 @@ export function consumeBattleSpares(
|
||||
const seenSlots = new Set<number>();
|
||||
const consumed = new Map<string, number>();
|
||||
for (const spawn of spawns) {
|
||||
const { slot, unit, backup } = spawn;
|
||||
const { slot, backup } = spawn;
|
||||
const unit = normalizeBackupUnitName(spawn.unit);
|
||||
if (session.spareSlots?.get(slot) !== unit || seenSlots.has(slot)) continue;
|
||||
seenSlots.add(slot);
|
||||
if (backup === DAILY_BACKUP) {
|
||||
recordDailyBackupSpawn(profile, session, spawn);
|
||||
recordDailyBackupSpawn(profile, session, { slot, unit, backup });
|
||||
continue;
|
||||
}
|
||||
if (dailySparesLeft(profile, session.startedAtSec) > 0
|
||||
|
||||
@@ -12,7 +12,7 @@ import { economyDifficulty, type BattleEconomy } from '../battle/battle-economy.
|
||||
import type { BattleMatchmaker } from '../battle/battle-matchmaker.ts';
|
||||
import { maxModeMrank, unitClassOfExpClass, unitClassOfTypeCode, type CraftRankEntry } from '../battle/battle-ranks.ts';
|
||||
import type { BattleSession, BattleSessionStore } from '../battle/battle-session-store.ts';
|
||||
import { DAILY_BACKUP, recordDailyBackupSpawn } from '../battle/battle-spares.ts';
|
||||
import { DAILY_BACKUP, normalizeBackupUnitName, recordDailyBackupSpawn } from '../battle/battle-spares.ts';
|
||||
import type { GameModes, OfferedGameMode } from '../game-modes/game-modes.ts';
|
||||
import { crewSlotVehicleOfCountry, crewVehiclesOfCountry } from '../profile/profile-crews.ts';
|
||||
import { dailySparesLeft } from '../profile/profile-daily-spares.ts';
|
||||
@@ -50,8 +50,9 @@ export function battleQueueRequests(deps: BattleQueueDependencies): Array<[strin
|
||||
return { error: 'BAD_PARAMS' };
|
||||
}
|
||||
const battle = deps.sessions.findForUser(sessionId, userId);
|
||||
if (!battle || battle.settled || battle.spareSlots?.get(slot) !== unit) return { error: 'BAD_PARAMS' };
|
||||
deps.profiles.updateWhen(userId, (profile) => recordDailyBackupSpawn(profile, battle, { slot, unit, backup: DAILY_BACKUP }));
|
||||
const normalizedUnit = normalizeBackupUnitName(unit);
|
||||
if (!battle || battle.settled || battle.spareSlots?.get(slot) !== normalizedUnit) return { error: 'BAD_PARAMS' };
|
||||
deps.profiles.updateWhen(userId, (profile) => recordDailyBackupSpawn(profile, battle, { slot, unit: normalizedUnit, backup: DAILY_BACKUP }));
|
||||
return {};
|
||||
}],
|
||||
];
|
||||
|
||||
@@ -114,9 +114,13 @@ void local_mp_report_backup_spawn(const char *unit_name, int32_t slot_id, const
|
||||
{
|
||||
__declspec(align(16)) uint8_t blk[LMP_BLK_SIZE];
|
||||
uint8_t *gsd = g_game_save_data ? *g_game_save_data : NULL;
|
||||
const char *slash;
|
||||
|
||||
if (gsd == NULL || fn_hud_notify_script == NULL || unit_name == NULL)
|
||||
return;
|
||||
slash = strrchr(unit_name, '/');
|
||||
if (slash != NULL && slash[1] != '\0')
|
||||
unit_name = slash + 1;
|
||||
memset(blk, 0, sizeof(blk));
|
||||
fn_blk_ctor(blk);
|
||||
fn_blk_set_str(blk, "unit", unit_name);
|
||||
|
||||
@@ -244,7 +244,8 @@ static uint8_t __fastcall hook_is_slot_ready_at_host(int32_t slot_id, const char
|
||||
mplayer = g_local_mp_mplayer ? *g_local_mp_mplayer : NULL;
|
||||
if (mplayer == NULL)
|
||||
return 1;
|
||||
return (*(uint32_t *)(mplayer + LMP_MP_OFF_BROKEN_SLOTS_MASK) & (1u << (uint32_t)slot_id)) == 0 ? 1 : 0;
|
||||
/* Allow broken slots whose backup has not been used yet; isCrewAvailableInSession enforces backup eligibility. */
|
||||
return (*(uint32_t *)(mplayer + LMP_MP_OFF_USED_SPARES_MASK) & (1u << (uint32_t)slot_id)) == 0 ? 1 : 0;
|
||||
}
|
||||
|
||||
int install_local_mp_player_hooks(void)
|
||||
|
||||
@@ -0,0 +1,2 @@
|
||||
lastRequestData = null
|
||||
lastSpawnUnitName = ""
|
||||
@@ -13,6 +13,7 @@
|
||||
"written_for": "2.61.0.37",
|
||||
"file": "scripts/respawn/respawn.nut",
|
||||
"edits": [
|
||||
{ "find": "find-backup-field.nut", "replace": "replace-backup-field.nut" },
|
||||
{
|
||||
"find": "find.nut",
|
||||
"replace": "replace.nut"
|
||||
|
||||
@@ -0,0 +1,3 @@
|
||||
lastRequestData = null
|
||||
wtoLastBackup = null
|
||||
lastSpawnUnitName = ""
|
||||
@@ -3,8 +3,9 @@
|
||||
let source = request == null ? null : this.getWtoBackupSourceForRequest(request)
|
||||
if (source != null) {
|
||||
let backup = this.getWtoBackupToken(request, source)
|
||||
if (backup == null || request?.wtoBackup != backup) {
|
||||
if (backup == null || this.wtoLastBackup != backup) {
|
||||
this.lastRequestData = null
|
||||
this.wtoLastBackup = null
|
||||
this.isApplyPressed = false
|
||||
this.checkReady()
|
||||
this.doSelectAircraft()
|
||||
|
||||
@@ -1,3 +1,3 @@
|
||||
if (this.lastRequestData?.wtoBackup == null)
|
||||
if (this.wtoLastBackup == null)
|
||||
markUsedItemCount(itemType.UNIVERSAL_SPARE, this.lastRequestData.spareUid)
|
||||
this.universalSpareUidForRespawn = ""
|
||||
@@ -1,8 +1,10 @@
|
||||
function sendWtoAircraftAndWeaponRequest(requestData, isSilent = false) {
|
||||
let wtoNdb = require("nestdb")
|
||||
if (!wtoNdb.ndbExists(["wto", "activeBattle"]))
|
||||
if (!wtoNdb.ndbExists(["wto", "activeBattle"])) {
|
||||
this.wtoLastBackup = null
|
||||
return requestAircraftAndWeaponWithSpare(requestData, requestData.idInCountry,
|
||||
requestData.respBaseId, requestData.spareUid)
|
||||
}
|
||||
let wtoBattle = wtoNdb.ndbTryRead(["wto", "activeBattle"])
|
||||
let wtoGuiRespawn = require("guiRespawn")
|
||||
let wtoChardRes = require("chardResearch")
|
||||
@@ -86,20 +88,27 @@
|
||||
wtoBlk.enabledMods = ";".join(wtoEnabledMods)
|
||||
wtoBlk.disabledMods = ";".join(wtoDisabledMods)
|
||||
wtoBlk.isSilentPreview = isSilent ? "1" : "0"
|
||||
// Keep backup metadata off requestData so checkReady()'s u.isEqual(lastRequestData, getSelectedRequestData()) stays true.
|
||||
local wtoBackupToken = null
|
||||
if (!isSilent) {
|
||||
let source = this.getWtoBackupSourceForRequest(requestData)
|
||||
let backup = this.getWtoBackupToken(requestData, source)
|
||||
if (backup == null)
|
||||
return -1
|
||||
if (backup != "") {
|
||||
requestData.wtoBackup <- backup
|
||||
wtoBackupToken = backup
|
||||
wtoBlk.wtoBackup = backup
|
||||
}
|
||||
if (source == "vehicle")
|
||||
if (source == "vehicle") {
|
||||
this.universalSpareUidForRespawn = ""
|
||||
requestData.spareUid = ""
|
||||
}
|
||||
}
|
||||
return wtoGuiRespawn.requestAircraftAndWeaponWithSlots(requestData, requestData.idInCountry,
|
||||
let wtoTaskId = wtoGuiRespawn.requestAircraftAndWeaponWithSlots(requestData, requestData.idInCountry,
|
||||
requestData.respBaseId, requestData.spareUid, wtoBlk, DataBlock())
|
||||
if (wtoTaskId >= 0)
|
||||
this.wtoLastBackup = wtoBackupToken
|
||||
return wtoTaskId
|
||||
}
|
||||
|
||||
function requestAircraftAndWeapon(requestData) {
|
||||
|
||||
@@ -172,20 +172,23 @@ function wtoOnLocalMpNuclearStrike(_ev) {
|
||||
function wtoOnLocalMpBackupSpawn(ev) {
|
||||
let { ndbTryRead, ndbWrite } = require("nestdb")
|
||||
let battle = ndbTryRead(["wto", "activeBattle"])
|
||||
if (battle?.backups == null || (ev?.unit ?? "") == "" || (ev?.backup ?? "") == "")
|
||||
// Native UnitInfo::name prefixes ground/naval units (e.g. "tankModels/cn_type_59"); keep the bare unit id.
|
||||
let parts = (ev?.unit ?? "").split("/")
|
||||
let unit = parts.len() > 0 ? parts.top() : ""
|
||||
if (battle?.backups == null || unit == "" || (ev?.backup ?? "") == "")
|
||||
return
|
||||
let slot = ev?.slot ?? -1
|
||||
let spawns = ndbTryRead(["wto", "battleLog", "spares"]) ?? []
|
||||
if (slot < 0 || spawns.findvalue(@(spawn) spawn.slot == slot) != null)
|
||||
return
|
||||
wtoAppendBattleLog("spares", { slot, unit = ev.unit, backup = ev.backup })
|
||||
wtoAppendBattleLog("spares", { slot, unit, backup = ev.backup })
|
||||
|
||||
let { DAILY_FREE_SPARE_UID } = require("%scripts/respawn/respawnDailyFreeSpare.nut")
|
||||
if (ev.backup == DAILY_FREE_SPARE_UID) {
|
||||
let path = ["wto", "battleLog", "dailyBackupsUsed"]
|
||||
ndbWrite(path, (ndbTryRead(path) ?? 0) + 1)
|
||||
let { matchingApiFunc } = require("%scripts/matching/api.nut")
|
||||
matchingApiFunc("wto_battle.daily_spare", @(_response) null, { sessionId = battle.sessionId, slot, unit = ev.unit })
|
||||
matchingApiFunc("wto_battle.daily_spare", @(_response) null, { sessionId = battle.sessionId, slot, unit })
|
||||
}
|
||||
else if (ev.backup != "vehicle") {
|
||||
let { markUsedItemCount } = require("%scripts/items/usedItemsInBattle.nut")
|
||||
|
||||
Reference in new issue
Block a user