const fs = require('fs') const base = 'C:/Users/ASUS/Documents/deepseek-harness/default-workspace/desktop-pet/src/' function patch(file, pairs) { const p = base + file let c = fs.readFileSync(p, 'utf8') for (const [from, to] of pairs) { if (!c.includes(from)) { console.log('MISS in', file, '::', from.slice(0, 70).replace(/\n/g, '\\n')) continue } c = c.replace(from, to) } fs.writeFileSync(p, c, 'utf8') } // ---- 崩溃修复:applyElapsed 防御旧存档缺 counters patch('shared/petState.ts', [ [ `export function applyElapsed(save: PetSave, seconds: number, now = Date.now()): void { if (seconds <= 0) return const m = seconds / 60`, `export function applyElapsed(save: PetSave, seconds: number, now = Date.now()): void { if (seconds <= 0) return if (!save.counters) save.counters = {} const m = seconds / 60` ] ]) patch('main/stateStore.ts', [ [ " if (!save || save.version !== 2 || !save.stats || !save.inventory) throw new Error('存档版本不匹配')\n if (typeof save.dailyGiftDay !== 'string') save.dailyGiftDay = ''", " if (!save || save.version !== 2 || !save.stats || !save.inventory) throw new Error('存档版本不匹配')\n if (!save.counters) save.counters = {}\n if (typeof save.dailyGiftDay !== 'string') save.dailyGiftDay = ''\n if (typeof save.sleeping !== 'boolean') save.sleeping = false" ] ]) console.log('crash fix patched')