Загрузка данных


(() => {
    const raw = window.GameInterface.storage.getItem("SF2User");
    if (!raw) {
        console.warn("Сохранение SF2User пока пустое. Сыграйте хотя бы один бой, чтобы игра создала файл профиля!");
        return;
    }

    // Декодируем 4 байта длины + UTF-8 XML
    const bin = atob(raw);
    const bytes = new Uint8Array(bin.length);
    for (let i = 0; i < bin.length; i++) bytes[i] = bin.charCodeAt(i);
    const xml = new TextDecoder().decode(bytes.slice(4));

    window._sf2Xml = xml;
    console.log("%c Профиль успешно расшифрован в window._sf2Xml!", "color: lime; font-weight: bold;");
    console.log(xml);
})();

(() => {
    if (!window._sf2Xml) {
        console.error("Сначала выполните Шаг 2!");
        return;
    }

    let xml = window._sf2Xml;

    // 1. Заменяем значения (регулярными выражениями)
    xml = xml.replace(/Money="\d+"/g, 'Money="9999999"');
    xml = xml.replace(/Bonus="\d+"/g, 'Bonus="99999"');
    xml = xml.replace(/Energy="\d+"/g, 'Energy="100"');
    xml = xml.replace(/CurrentEnergy="\d+"/g, 'CurrentEnergy="100"');

    // 2. Кодируем обратно в бинарный формат (4 байта длины + UTF-8 + Base64)
    const xmlBytes = new TextEncoder().encode(xml);
    const len = xmlBytes.length;
    const out = new Uint8Array(4 + len);
    out[0] = len & 0xFF;
    out[1] = (len >> 8) & 0xFF;
    out[2] = (len >> 16) & 0xFF;
    out[3] = (len >> 24) & 0xFF;
    out.set(xmlBytes, 4);

    let bin = "";
    for (let i = 0; i < out.length; i++) bin += String.fromCharCode(out[i]);
    const newBase64 = btoa(bin);

    // 3. Записываем в GameInterface
    window.GameInterface.storage.setItem("SF2User", newBase64);

    console.log("%c СОХРАНЕНО! Перезагрузите страницу (F5).", "color: lime; font-size: 16px; font-weight: bold;");
})();