
<!DOCTYPE html>

<html lang="ja">
<head>
<meta charset="utf-8"/>
<title>スクリプト3</title>
<meta content="width=device-width, initial-scale=1.0" name="viewport"/>
<link href="https://fonts.googleapis.com/css2?family=Zen+Kurenaido&amp;display=swap" rel="stylesheet"/>
<style>

/* モダンなカスタムチェックボックス */
.form-row input[type="checkbox"] {
  display: none;
}

.form-row input[type="checkbox"] + label {
  position: relative;
  padding-left: 28px;
  cursor: pointer;
  line-height: 24px;
  display: inline-block;
  color: #fff;
}

.form-row input[type="checkbox"] + label::before {
  content: "";
  position: absolute;
  left: 0;
  top: 4px;
  width: 18px;
  height: 18px;
  border: 2px solid #0ff;
  border-radius: 4px;
  background: transparent;
  box-shadow: 0 0 4px rgba(0,255,255,0.4);
  transition: background 0.3s, box-shadow 0.3s;
}

.form-row input[type="checkbox"]:checked + label::before {
  background-color: #0ff;
  box-shadow: 0 0 8px #0ff;
}

.form-row input[type="checkbox"]:checked + label::after {
  content: '✓';
  position: absolute;
  left: 4px;
  top: 2px;
  font-size: 14px;
  color: black;
}

    body {
      margin: 0;
      padding: 0;
      background: linear-gradient(135deg, #1f1c2c, #928dab);
      font-family: 'Zen Kurenaido', sans-serif;
      color: white;
      backdrop-filter: blur(6px);
      -webkit-backdrop-filter: blur(6px);
    }

    .tabs-container {
      display: flex;
      justify-content: space-around;
      background: rgba(255, 255, 255, 0.05);
      backdrop-filter: blur(8px);
      border-radius: 12px;
      margin: 20px;
      box-shadow: 0 0 8px rgba(255, 255, 255, 0.1);
    }
    


    .tab {
      flex: 1;
      text-align: center;
      padding: 12px 0;
      cursor: pointer;
      font-size: 16px;
      font-weight: bold;
      border-radius: 8px;
      color: white;
      transition: background 0.3s, box-shadow 0.3s;
    }

    .tab:hover,
    .tab.active {
      background: rgba(0, 255, 255, 0.1);
      
    }

    .content {
      display: none;
      margin: 20px;
      padding: 20px;
      background: rgba(255, 255, 255, 0.05);
      border-radius: 12px;
      box-shadow: 0 0 15px rgba(255, 255, 255, 0.05);
    }

    .active-content {
      display: block;
    }

    .form-group {
      margin-bottom: 20px;
    }

    textarea, input[type="text"] {
      width: 100%;
      padding: 10px;
      background: rgba(255, 255, 255, 0.05);
      border: 1px solid rgba(255, 255, 255, 0.2);
      border-radius: 8px;
      color: white;
      font-size: 14px;
      outline: none;
      transition: border 0.3s, background 0.3s;
    }

    textarea:focus, input[type="text"]:focus {
      background: rgba(0, 255, 255, 0.1);
      border: 1px solid rgba(255,255,255,0.2);
    }

    .btn {
      padding: 10px 20px;
      background: rgba(255, 255, 255, 0.1);
      border: 1px solid rgba(255,255,255,0.2);
      border-radius: 8px;
      color: white;
      font-weight: bold;
      cursor: pointer;
      transition: background 0.3s, box-shadow 0.3s;
    }

    .btn:hover {
      background: rgba(255, 255, 255, 0.15);
      
    }

    .checkbox-container {
      display: flex;
      align-items: center;
      margin-bottom: 10px;
    }

    .checkbox-container input[type="checkbox"] {
  appearance: none;
  width: 20px;
  height: 20px;
  border: 2px solid #0ff;
  border-radius: 4px;
  margin: 0;
  vertical-align: middle;
  background: transparent;
  position: relative;
  cursor: pointer;
}

    .checkbox-container input[type="checkbox"]:checked::before {
      content: " ";
      color: white;
      position: absolute;
      left: 4px;
      top: 0px;
    }

    .alert {
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%);
      background: rgba(0, 0, 0, 0.7);
      padding: 20px 40px;
      border-radius: 12px;
      color: white;
      box-shadow: 0 0 20px rgba(0, 255, 255, 0.5);
      display: none;
    }

  
#save-button, #load-button {
  padding: 10px 20px;
  background: rgba(0, 255, 128, 0.2);
  border: 1px solid #0f8;
  border-radius: 8px;
  color: white;
  font-weight: bold;
  cursor: pointer;
  transition: background 0.3s, box-shadow 0.3s;
}
#save-button:hover, #load-button:hover {
  background: rgba(0, 255, 128, 0.4);
  box-shadow: 0 0 10px #0f8, 0 0 20px #0f8;
}


  .form-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  margin: 6px 0;
}

  .form-row label {
  min-width: 50px;
  margin: 0;
  font-size: 14px;
  height: 32px;
  line-height: 32px;
}
  
.form-row textarea {
  width: 100px;
  height: 32px;
  font-size: 14px;
  resize: none;
  padding: 6px 8px;
  margin: 0;
  text-align: right;
  box-sizing: border-box;
}
  .form-row .action {
    padding: 6px 14px;
    background: rgba(0, 200, 255, 0.2);
    border: 1px solid #0ff;
    color: white;
    font-weight: bold;
    border-radius: 6px;
    cursor: pointer;
    transition: 0.3s;
  }
  .form-row .action:hover {
    background: rgba(0, 200, 255, 0.4);
    box-shadow: 0 0 8px #0ff;
  }

.label-glow {
  background: rgba(0, 255, 255, 0.2);
  box-shadow: 0 0 10px #0ff;
  border-radius: 6px;
  padding: 4px;
}

.modal {
    display: none;
    position: fixed;
    z-index: 99999;
    left: 0;
    top: 0;
    width: 100%;
    height: 100%;
    overflow: auto;
    background-color: rgba(0, 0, 0, 0.6);
}
.modal-content {
    background-color: #111;
    margin: 15% auto;
    padding: 20px;
    border: 1px solid #00c6ff;
    width: 300px;
    border-radius: 10px;
    color: white;
    text-align: center;
}
.close-btn {
    float: right;
    font-size: 24px;
    cursor: pointer;
}

.form-row input[type="checkbox"] { display: none; }
  
.form-row input[type="checkbox"] + label {
  display: inline-block;
  position: relative;
  padding-left: 0;
  margin: 0;
  height: 32px;
  line-height: 22px;
  font-size: 14px;
  cursor: pointer;
}

.form-row input[type="checkbox"] + label:last-child { margin-bottom: 0; }

.form-row input[type="checkbox"] + label:before {
  content: '';
  display: block;
  width: 20px;
  height: 20px;
  border: 1px solid #cb49e5;
  position: absolute;
  left: 0;
  top: 0;
  opacity: .6;
  -webkit-transition: all .12s, border-color .08s;
  transition: all .12s, border-color .08s;
}

.form-row input[type="checkbox"]:checked + label:before {
  width: 10px;
  top: -5px;
  left: 5px;
  border-radius: 0;
  opacity: 1;
  border-top-color: transparent;
  border-left-color: transparent;
  -webkit-transform: rotate(45deg);
  transform: rotate(45deg);
}


.form-row {
  display: flex;
  align-items: center;
  justify-content: flex-start;
  gap: 10px;
  margin: 6px 0;
}

.form-row label {
  min-width: 50px;
  margin: 0;
  font-size: 14px;
  height: 34px;
  line-height: 34px;
}

.form-row textarea {
  width: 100px;
  height: 32px;
  font-size: 14px;
  resize: none;
  padding: 6px 8px;
  margin: 0;
  text-align: right;
  box-sizing: border-box;
}
.form-row {
  display: flex;
  align-items: center;
  justify-content: space-between; /* ラベル左寄せ・テキストエリア右寄せの基本 */
  gap: 10px;
  margin: 6px 0;
}

.form-row label {
  flex: 1;
  text-align: center; /* ラベル中央揃え */
  font-size: 14px;
  height: 32px;
  line-height: 32px;
}

.form-row textarea {
  width: 100px;
  height: 32px;
  font-size: 14px;
  resize: none;
  padding: 6px 8px;
  margin: 0;
  box-sizing: border-box;
  text-align: right;
}
.form-row input[type="checkbox"]:checked + label::after {
  display: none !important;
}

</style>
</head>
<body>
<div id="slide-switcher" style="position: fixed; top: 10px; right: 10px; z-index: 1000; margin-top: 60px;">
</div>

<div id="slide1">
<div class="tabs-container">
<div class="tab active" onclick="changeTab('tab1')">Ⅰ</div>
<div class="tab" onclick="changeTab('tab2')">Ⅱ</div>
<div class="tab" onclick="changeTab('tab3')">Ⅲ</div>
<div class="tab" onclick="changeTab('tab4')">Ⅳ</div>
<div class="tab" onclick="changeTab('tab5')">Ⅴ</div>
<div class="tab" onclick="changeTab('tab6')">Ⅵ</div>
<div class="tab" onclick="changeTab('tab7')">Ⅶ</div>
<div class="tab" onclick="changeTab('tab8')">Ⅷ</div>
</div>
<div class="content active-content" id="tab1">
<button class="btn" onclick="autoFillAll()">全自動入力</button>
      <div class="form-row">
          <input id="nekokan" type="checkbox">
          <label for="nekokan">猫缶</label>
          <textarea name="nekokan" placeholder="例58000">
          </textarea>
        </div>
        <div class="form-row">
          <input id="xp" type="checkbox">
          <label for="xp">XP</label>
          <textarea name="xp" placeholder="例99999999">
          </textarea>
        </div>
        <div class="form-row">
          <input id="np" type="checkbox">
          <label for="np">NP</label>
          <textarea name="np" placeholder="例9999">
          </textarea>
        </div>

</div>
<div class="content" id="tab2">
        <div class="form-row">
          <input id="silverTick" type="checkbox">
          <label for="silverTick">銀チケ</label>
          <textarea name="silverTick" placeholder="例999">
          </textarea>
        </div>
        <div class="form-row">
          <input id="goldTick" type="checkbox">
          <label for="goldTick">金チケ</label>
          <textarea name="goldTick" placeholder="例999">
          </textarea>
        </div>
        <div class="form-row">
          <input id="プラチケ" type="checkbox">
          <label for="プラチケ">プラチケ</label>
          <textarea name="プラチケ" placeholder="例29">
          </textarea>
        </div>
        <div class="form-row">
          <input id="レジェチケ" type="checkbox">
          <label for="レジェチケ">レジェチケ</label>
          <textarea name="レジェチケ" placeholder="例9">
          </textarea>
        </div>
</div>
<div class="content" id="tab3">
       <div class="form-row">
          <input id="catseyes" type="checkbox">
          <label for="catseyes">キャッツアイ</label>
          <textarea name="catseyes" placeholder="例999">
          </textarea>
        </div>
        <div class="form-row">
          <input id="matt" type="checkbox">
          <label for="matt">マタタビ</label>
          <textarea name="matt" placeholder="例99">
          </textarea>
        </div>
        <div class="form-row">
          <input id="vitamin" type="checkbox">
          <label for="vitamin">ネコビタ</label>
          <textarea name="vitamin" placeholder="例999">
          </textarea>
        </div>
        <div class="form-row">
          <input id="item" type="checkbox">
          <label for="item">アイテム</label>
          <textarea name="item" placeholder="例900">
          </textarea>
        </div>
        <div class="form-row">
          <input id="城素材" type="checkbox">
          <label for="城素材">城素材</label>
          <textarea name="城素材" placeholder="例999">
          </textarea>
        </div>
        <div class="form-row">
          <input id="leadership" type="checkbox">
          <label for="leadership">リーダーシップ</label>
          <textarea name="leadership" placeholder="例500">
          </textarea>
        </div>








</div>
<div class="content" id="tab4">
 <div class="form-row">
<input id="stage" onchange="AllStageUnlock()" type="checkbox"><label for="stage">ステージ解放</label>
</div>

<div class="form-row">
<input id="legend" onchange="legend()" type="checkbox"><label for="legend">レジェステ</label>
</div>
          <div class="form-row">
            <input id="treasure" onchange="お宝()" type="checkbox">
            <label for="treasure">最高のお宝</label>
          </div>
          <div class="form-row">
            <input id="HPSwitch" onchange="updateHP()" type="checkbox">
            <label for="HPSwitch">城HP</label>
          </div>
          <div class="form-row">
            <input id="gama" onchange="gama()" type="checkbox">
            <label for="gama">ガマトト</label>
          </div>
          <div class="form-row">
            <input id="jyosyu" onchange="jyosyu()" type="checkbox">
            <label for="jyosyu">助手</label>
          </div>
        </div>

</div>
<div class="content" id="tab5">
        <div class="form-row">
          <input id="レベマ" type="checkbox">
          <label for="レベマ">&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;プラス値</label>
          <textarea name="レベマ" placeholder="例90">
          </textarea>
        </div>
        <div class="form-row">
          <input id="charcter" onchange="キャラ解放()" type="checkbox">
          <label for="charcter">全キャラ解放</label>
        </div>
        <div class="form-row">
          <input id="three" onchange="第三形態()" type="checkbox">
          <label for="three">第三形態</label>
        </div>
        </div>
<div class="content" id="tab6">
      <div class="form-row">
              <input id="time" type="checkbox">
              <label for="time">&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;&emsp;プレイ時間</label>
              <textarea name="time" placeholder="例500(約1年くらい)">
              </textarea>
            </div>

            <div class="form-row">
              <input id="unlimit" onchange="unlimit()" type="checkbox">
              <label for="unlimit">統率力</label>
            </div>
            <div class="form-row">
              <input id="cm" onchange="広告非表示()" type="checkbox">
            </div>
            
        <div class="form-row">
          <input id="adblock" onchange="広告非表示()" type="checkbox">
          <label for="adblock">広告非表示</label>
        </div>
<div class="form-row">
              <input id="進化Switch" onchange="進化スキップ()" type="checkbox">
              <label for="進化Switch">進化スキップ</label>
            </div>
    </div>
<div class="content" id="tab7">
    <div id="selectedCharacters">
            </div>
            <button onclick="batchUnlock()">まとめて解放</button>
            <button onclick="batchDelete()">まとめて削除</button>
            <!-- 形態選択 -->
            <button onclick="openModal('levelModal')">レベルMax</button>
            <button onclick="openModal('formModal')">形態を選択</button>
            <button onclick="removeSelectedCharacters()">選択解除</button>
        <div id="formModal" class="modal">
          <div class="modal-content">
            <span class="close-btn" onclick="closeModal('formModal')">×</span>
            <h3>形態を選択</h3>
            <div>
              <label>
                <input type="radio" name="formSelect" value="0" checked>第1形態</label>
              <br>
              <label>
                <input type="radio" name="formSelect" value="1">第2形態</label>
              <br>
              <label>
                <input type="radio" name="formSelect" value="2">第3形態</label>
            </div>
            <button onclick="applySelectedForm(); closeModal('formModal');">適用</button>
          </div>
        </div>
        <div id="levelModal" class="modal">
          <div class="modal-content">
            <span class="close-btn" onclick="closeModal('levelModal')">×</span>
            <h3>プラス値を入力</h3>
            <div>
              <label><input id="lv-m" type="input" placefolder="プラス値を入力"></label>
            </div>
            <button onclick="lvMax(); closeModal('levelModal');">適用</button>
          </div>
        </div>
          <p style="color:#ccc;"></p>
          <div class="form-row">
            <label for="searchInput">検索</label>
            <input type="text" id="searchInput" placeholder="正しく記入">
          </div>
          <div id="characterList">
          </div>
        <p style="color:#ccc;">選択キャラ：</p>
    
</div>


<div class="content" id="tab8">
<div style="margin-top: 20px; display: flex; gap: 12px;">
<button id="save-button" onclick="saveData()">保存</button>
<button id="load-button" onclick="loadData()">復元</button>
</div>
</div>

<div style="margin: 20px;">
  <button class="btn" onclick="applyManualInputs()">入力値を反映</button>
</div>

<div class="alert" id="alertBox">これはアラートです</div>
<script>
    function changeTab(tabId) {
      const tabs = document.querySelectorAll('.tab');
      const contents = document.querySelectorAll('.content');

      tabs.forEach(tab => tab.classList.remove('active'));
      contents.forEach(content => content.classList.remove('active-content'));

      document.querySelector(`[onclick="changeTab('${tabId}')"]`).classList.add('active');
      document.getElementById(tabId).classList.add('active-content');
    }

    function showAlert(message) {
      const alertBox = document.getElementById("alertBox");
      alertBox.textContent = message;
      alertBox.style.display = "block";
      setTimeout(() => {
        alertBox.style.display = "none";
      }, 2000);
    }
  
function lvMaxFromValue(val) {
  if (!val || isNaN(val)) return;
  const value = parseInt(val);
  const charCount = offsets.character数;
  const addr = offsets.キャラレベル;
  for (let i = 0; i < charCount; i++) {
    h5gg.setValue(addr + (i * 4), value, "I32");
  }
}




// タブ4,5,6のチェックボックスをロックし続ける（定期実行）
const lockMap = {
  stage: () => AllStageUnlock(),
  legend: () => legend(),
  treasure: () => お宝(),
  HPSwitch: () => updateHP(),
  gama: () => gama(),
  jyosyu: () => jyosyu(),
  charcter: () => キャラ解放(),
  three: () => 第三形態(),
  unlimit: () => unlimit(),
  cm: () => 広告非表示(),
  進化Switch: () => 進化スキップ()
};

setInterval(() => {
  for (const id in lockMap) {
    const checkbox = document.getElementById(id);
    if (checkbox && checkbox.checked) {
      try {
        lockMap[id]();
      } catch (e) {
        console.warn("Lock function error for", id, e);
      }
    }
  }
}, 1000); // 1秒ごとに監視



function autoFillAll() {
  const autoValues = {
    nekokan: "58000",
    xp: "99999999",
    np: "9999",
    silverTick: "999",
    goldTick: "999",
    プラチケ: "29",
    レジェチケ: "9",
    catseyes: "999",
    matt: "99",
    vitamin: "999",
    item: "900",
    城素材: "999",
    leadership: "500",
    レベマ: "90",
    time: "500"
  };

  Object.keys(autoValues).forEach(id => {
    const textarea = document.querySelector(`textarea[name="${id}"]`);
    if (textarea) {
      textarea.value = autoValues[id];
    }
    const checkbox = document.getElementById(id);
    if (checkbox) {
      checkbox.checked = true;
    }
  });

  const callFuncs = {
    stage: AllStageUnlock,
    legend: legend,
    treasure: お宝,
    HPSwitch: updateHP,
    gama: gamaFunc,
    jyosyu: jyosyuFunc,
    charcter: キャラ解放,
    three: 第三形態,
    unlimit: unlimit,
    cm: 広告非表示,
    進化Switch: 進化スキップ
  };

  Object.keys(callFuncs).forEach(id => {
    const checkbox = document.getElementById(id);
    if (checkbox) {
      checkbox.checked = true;
      if (typeof callFuncs[id] === "function") {
        callFuncs[id]();
      }
    }
  });

  showAlert("全自動入力が完了しました！");
}



// custom patch start

function setValueAndClearNext(name, value) {
  if (!offsets[name]) return;

  try {
    const baseAddr = offsets[name];
    h5gg.setValue(baseAddr, value, "I32");
    h5gg.setValue(baseAddr + 4, 0, "I32"); // 次のアドレスを0にする
  } catch (e) {
    console.warn(`setValueAndClearNext failed for ${name}:`, e);
  }
}


function applyManualInputs() {
  const textareas = document.querySelectorAll('textarea');
  const specialTargets = ["nekokan", "xp", "np", "silverTick", "goldTick", "レジェチケ", "プラチケ"];

  textareas.forEach(textarea => {
    const name = textarea.name;
    const val = textarea.value.trim();
    if (!val) return;

    const parsed = parseInt(val);
    if (isNaN(parsed)) return;

    if (specialTargets.includes(name)) {
      setValueAndClearNext(name, parsed);
    } else {
      try {
        if (typeof window[name] === "function") {
          window[name](parsed);
        } else if (offsets[name]) {
          h5gg.setValue(offsets[name], parsed, "I32");
        }
      } catch (e) {
        console.warn(`Failed to set ${name}`, e);
      }
    }
  });

  showAlert("入力値をすべて反映しました！");
}

// custom patch end
function dummyApplyManualInputs() {
  const textareas = document.querySelectorAll('textarea');
  textareas.forEach(textarea => {
    const name = textarea.name;
    const val = textarea.value.trim();
    if (!val) return;

    const parsed = parseInt(val);
    if (isNaN(parsed)) return;

    try {
      // 関数が定義されていれば呼び出し（非同期関数含む）
      if (typeof window[name] === "function") {
        window[name](parsed);
      }
      // オフセットが定義されていれば直接書き込み
      else if (offsets[name]) {
        h5gg.setValue(offsets[name], parsed, "I32");
      }
    } catch (e) {
      console.warn(`Failed to set ${name}`, e);
    }
  });

  showAlert("入力値をすべて反映しました！");
}

</script>
<!-- end of slide1 -->
<div id="slide2" style="display:none;">
<div class="tabs-container">
<div class="tab active" onclick="changeTab('tab21')">Ⅰ</div>
<div class="tab" onclick="changeTab('tab22')">Ⅱ</div>
<div class="tab" onclick="changeTab('tab23')">Ⅲ</div>
<div class="tab" onclick="changeTab('tab24')">Ⅳ</div>
<div class="tab" onclick="changeTab('tab25')">Ⅴ</div>
<div class="tab" onclick="changeTab('tab26')">Ⅵ</div>
<div class="tab" onclick="changeTab('tab27')">Ⅶ</div>
<div class="tab" onclick="changeTab('tab28')">Ⅷ</div>
</div>
<div class="content active-content" id="tab21"><h2>スライド2 - タブ1</h2></div>
<div class="content" id="tab22"><h2>スライド2 - タブ2</h2></div>
<div class="content" id="tab23"><h2>スライド2 - タブ3</h2></div>
<div class="content" id="tab24"><h2>スライド2 - タブ4</h2></div>
<div class="content" id="tab25"><h2>スライド2 - タブ5</h2></div>
<div class="content" id="tab26"><h2>スライド2 - タブ6</h2></div>
<div class="content" id="tab27"><h2>スライド2 - タブ7</h2></div>
<div class="content" id="tab28"><h2>スライド2 - タブ8</h2></div>
</div>
<script>
  function switchSlide(id) {
    // すべて非表示
    document.getElementById('slide1').style.display = 'none';
    document.getElementById('slide2').style.display = 'none';

    // 指定されたスライドを表示
    document.getElementById(id).style.display = 'block';
  }


function autoFillAll() {
  const autoValues = {
    nekokan: "58000",
    xp: "99999999",
    np: "9999",
    silverTick: "999",
    goldTick: "999",
    プラチケ: "29",
    レジェチケ: "9",
    catseyes: "999",
    matt: "99",
    vitamin: "999",
    item: "900",
    城素材: "999",
    leadership: "500",
    レベマ: "90",
    time: "500"
  };

  Object.keys(autoValues).forEach(id => {
    const textarea = document.querySelector(`textarea[name="${id}"]`);
    if (textarea) {
      textarea.value = autoValues[id];
    }
    const checkbox = document.getElementById(id);
    if (checkbox) {
      checkbox.checked = true;
    }
  });

  const callFuncs = {
    stage: AllStageUnlock,
    legend: legend,
    treasure: お宝,
    HPSwitch: updateHP,
    gama: gamaFunc,
    jyosyu: jyosyuFunc,
    charcter: キャラ解放,
    three: 第三形態,
    unlimit: unlimit,
    cm: 広告非表示,
    進化Switch: 進化スキップ
  };

  Object.keys(callFuncs).forEach(id => {
    const checkbox = document.getElementById(id);
    if (checkbox) {
      checkbox.checked = true;
      if (typeof callFuncs[id] === "function") {
        callFuncs[id]();
      }
    }
  });

  showAlert("全自動入力が完了しました！");
}



// custom patch start

function setValueAndClearNext(name, value) {
  if (!offsets[name]) return;

  try {
    const baseAddr = offsets[name];
    h5gg.setValue(baseAddr, value, "I32");
    h5gg.setValue(baseAddr + 4, 0, "I32"); // 次のアドレスを0にする
  } catch (e) {
    console.warn(`setValueAndClearNext failed for ${name}:`, e);
  }
}


function applyManualInputs() {
  const textareas = document.querySelectorAll('textarea');
  const specialTargets = ["nekokan", "xp", "np", "silverTick", "goldTick", "レジェチケ", "プラチケ"];

  textareas.forEach(textarea => {
    const name = textarea.name;
    const val = textarea.value.trim();
    if (!val) return;

    const parsed = parseInt(val);
    if (isNaN(parsed)) return;

    if (specialTargets.includes(name)) {
      setValueAndClearNext(name, parsed);
    } else {
      try {
        if (typeof window[name] === "function") {
          window[name](parsed);
        } else if (offsets[name]) {
          h5gg.setValue(offsets[name], parsed, "I32");
        }
      } catch (e) {
        console.warn(`Failed to set ${name}`, e);
      }
    }
  });

  showAlert("入力値をすべて反映しました！");
}

// custom patch end
function dummyApplyManualInputs() {
  const textareas = document.querySelectorAll('textarea');
  textareas.forEach(textarea => {
    const name = textarea.name;
    const val = textarea.value.trim();
    if (!val) return;

    const parsed = parseInt(val);
    if (isNaN(parsed)) return;

    try {
      // 関数が定義されていれば呼び出し（非同期関数含む）
      if (typeof window[name] === "function") {
        window[name](parsed);
      }
      // オフセットが定義されていれば直接書き込み
      else if (offsets[name]) {
        h5gg.setValue(offsets[name], parsed, "I32");
      }
    } catch (e) {
      console.warn(`Failed to set ${name}`, e);
    }
  });

  showAlert("入力値をすべて反映しました！");
}

</script>
<script>
function showTab (tabName) {
    document.querySelectorAll('.container').forEach(c => c.classList.remove('active'));
    document.getElementById(tabName).classList.add('active');
}

function triggerGlow (button) {
    button.classList.remove('clicked');
    void button.offsetWidth;
    button.classList.add('clicked');
}

function switchTab (n) {
    document.querySelectorAll('.tab-btn').forEach(b => b.classList.remove('active'));
    document.querySelectorAll('.tab-content').forEach(c => c.classList.remove('active'));
    document.querySelector('.tab-btn:nth-child(' + n + ')').classList.add('active');
    document.getElementById('tab-' + n).classList.add('active');
}
async function time (a) {
    if (!isNaN(Number(a))) {
        h5gg.setValue(offsets.time, a * 1800 * 60, 'I32');
    } else {
        customAlert('有効な数字を入力してください');
    }
}
let baseAddr = 0;
let offsets = {};
let currentValue = 0;
window.onload = function () {
    h5gg.clearResults();
    h5gg.searchNumber('32400', 'I32', '0x100000000', '0x110000000');
    baseAddr = Number(h5gg.getResults('1')[0].address) ? Number(h5gg.getResults('1')[0].address):0;
    h5gg.clearResults();
    offsets = {
        xp: baseAddr + 0x40, //   
        np: baseAddr + 0x48, //
        nekokan: baseAddr - 0x130, //
        character: baseAddr + 0x3aa38, //(neko)
        キャラレベル: baseAddr + 0x3b6e8, //
        キャラ形態: baseAddr + 0x3d040, //
        character数: 811, //
        unlimit: baseAddr + 0x3dd3c, //
        item: baseAddr + 0x3dda0, //
        silverTick: baseAddr + 0x2eed4c, //
        goldTick:   baseAddr + 0x2eed54, //
        gachaSkip: baseAddr + 0x2f0630,
        プラチケ: baseAddr - 0x9188, //
        レジェチケ: baseAddr - 0x9180, //
        一億チケ: baseAddr - 0x8e50,
        城HP: baseAddr + 0x7e9b8, //
        catseye: baseAddr + 0x3f8d44, //↓
        vitamin: baseAddr + 0x3f8d44 + 0x30, //↓
        城素材: baseAddr + 0x3f8d44 + 0x48, //↓の順で並んでる
        AllStageUnlock: baseAddr + 0x69c,
        stage: baseAddr + 0x69c + 0x2c,
        treasure: baseAddr + 0x69c + 0x84c,
        広告非表示: baseAddr + 0x3FE8A0, //catseye
        進化スキップ: baseAddr + 0x3D9A58,
        legend: baseAddr + 0x2ffcb8,
        legendClear: baseAddr + 0x33d230, //
        trueLegend: baseAddr + 0x2f7f80,
        trueLegendClear: baseAddr + 0x33d154,
        leadership: baseAddr - 0x98d6,
        time: baseAddr + 0x37B86C, //
        matt: baseAddr + 0x3BD0C0,
 gama: baseAddr + 0x3dc3b8,
                jyosyu: baseAddr + 0x3e04e0//
    };
    currentValue = Number(h5gg.getValue(offsets.character, "I32"));
}
let locker = null;
const count = 1;

function clearResult () {
    h5gg.clearResults();
    totalClicks = 0;
    document.getElementById("resultCount").textContent = "検索結果数:";
}

function updateGachaSkip () {
    const bottonSwitch = document.getElementById("gachaSkipSwitch");
    gachaSkipEnabled = bottonSwitch.checked;
    if (gachaSkipEnabled) {
        locker = setInterval(function () {
            for (var i = 0; i < count; i++) {
                h5gg.setValue(offsets.gachaSkip, "0", "I32");
            }
        }, 500);
    } else {
        if (locker !== null) {
            clearInterval(locker);
            locker = null;
        }
    }
}

function 進化スキップ () {
    const あSwitch = document.getElementById("進化Switch");
    進化SkipEnabled = あSwitch.checked;
    if (進化SkipEnabled) {
        locker = setInterval(function () {
            for (var i = 0; i < count; i++) {
                h5gg.setValue(offsets.進化スキップ, "0", "I32");
            }
        }, 1200);
    } else {
        if (locker !== null) {
            clearInterval(locker);
            locker = null;
        }
    }
}

function 広告非表示 () {
    h5gg.setValue(offsets.広告非表示, "99999", "I32");
    customAlert('完了', '');
}

function updateHP () {
    const hpswitch = document.getElementById("HPSwitch");
    HPEnabled = hpswitch.checked;
    if (HPEnabled) {
        locker = setInterval(function () {
            for (var i = 0; i < count; i++) {
                h5gg.setValue(offsets.城HP, "0", "I32");
            }
        }, 500);
    } else {
        if (locker !== null) {
            clearInterval(locker);
            locker = null;
        }
    }
}

function cm () {
    h5gg.clearResults();
    h5gg.searchNumber('134', 'I32', '0x100000000', '0x110000000');
    h5gg.searchNearby('20', 'I32', '0x10');
    h5gg.searchNumber('134', 'I32', '0x100000000', '0x110000000');
    return h5gg.getResults('1')[0].address + 0x8;
}

function AllStageUnlock () {
    for (var i = 0; i < 10; i++) {
        h5gg.setValue(offsets.AllStageUnlock + (i * 4), "48", "I32");
    }
    h5gg.setValue(offsets.AllStageUnlock + (i * 4), "0", "I32");
}

function satelite (address, offset) {
    let value = h5gg.getValue(address, 'I32');
    h5gg.setValue((address + offset), value - 8, 'I32');
}

function treasure (address, offset) {
    for (let k = 0; k < 48; k++) {
        h5gg.setValue((address + (k * 4)), 3, 'I32');
    }
    h5gg.setValue((address + offset), 0, 'I32');
}

function お宝 () {
    for (let i = 0; i < 10; i++) {
        satelite((offsets.stage + (0xD0 * i)), 0xCC);
        treasure(offsets.treasure + (0xC8 * i), 0xC4);
    }
}
let totalClicks = 0;

function Search (Number) {
    try {
        var count = 0;
        totalClicks++;
        document.getElementById("resultCount").textContent = totalClicks;
        if (totalClicks === 1) {
  