<!DOCTYPE html>
<html>
<head>
  <meta name="viewport" content="width=device-width,initial-scale=1.0,user-scalable=no"/>
  <meta charset="utf-8">
  <link href="https://fonts.googleapis.com/css2?family=PT+Serif&display=swap" rel="stylesheet">
  <style>
    body {
      font-family: -apple-system, BlinkMacSystemFont, "Segoe UI", Roboto, "Helvetica Neue", Arial, sans-serif;
      background-color: transparent;
      margin: 0;
      color: #fff;
      overflow: hidden;
      touch-action: none;
      width: 100vw;
      height: 100vh;
    }

    .intro {
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%) scale(0.7);
      font-size: 12px;
      line-height: 1.2;
      font-weight: bold;
      z-index: 1001;
      padding: 8px;
      border-radius: 0;
      animation: fadeIn 0.3s ease-out forwards, fadeOut 0.3s 3s ease-out forwards;
      background-color: rgba(0, 0, 0, 0.8);
      width: 80%;
      max-width: 180px;
      box-shadow: 0 0 5px rgba(0, 0, 0, 0.5);
      display: flex;
      align-items: center;
      justify-content: center;
      flex-direction: column;
      text-align: center;
      will-change: transform, opacity;
    }

    .mod-menu {
      position: fixed;
      top: 50%;
      left: 50%;
      transform: translate(-50%, -50%) scale(0);
      background-color: rgba(0, 0, 0, 0.8);
      border-radius: 0;
      z-index: 1000;
      animation: popIn 0.25s cubic-bezier(0.2, 0.8, 0.4, 1.5) 3.3s forwards;
      width: 220px;
      height: auto;
      max-height: 80vh;
      will-change: transform;
      cursor: grab;
      opacity: 0;
      box-shadow: 0 0 10px rgba(0, 0, 0, 0.6);
      border: 1px solid #333;
      padding-bottom: 10px;
    }

    .mod-header {
      padding: 8px;
      border-radius: 0;
      cursor: grab;
      user-select: none;
      -webkit-user-select: none;
      text-align: center;
      background-color: rgba(0, 0, 0, 0.8);
      border-bottom: 1px solid #333;
    }

    .scroll-container {
      overflow-y: auto;
      overflow-x: hidden;
      height: calc(100% - 40px);
      padding: 5px;
      width: calc(100% - 10px);
      -webkit-overflow-scrolling: touch;
      background-color: rgba(0, 0, 0, 0.8);
    }

    @keyframes fadeIn {
      0% { opacity: 0; transform: translate(-50%, -50%) scale(0.7) translateY(-20px); }
      100% { opacity: 1; transform: translate(-50%, -50%) scale(0.7); }
    }

    @keyframes fadeOut {
      0% { opacity: 1; transform: translate(-50%, -50%) scale(0.7); }
      100% { opacity: 0; transform: translate(-50%, -50%) scale(0.7) translateY(-20px); display: none; }
    }

    @keyframes popIn {
      0% { transform: translate(-50%, -50%) scale(0); opacity: 0; }
      100% { transform: translate(-50%, -50%) scale(1); opacity: 1; }
    }

    .mod-title {
      color: #fff;
      font-size: 14px;
      white-space: nowrap;
      margin: 0;
      padding: 5px 0;
      display: inline-block;
      pointer-events: none;
    }

    .switch-container {
      display: flex;
      align-items: center;
      justify-content: space-between;
      border-radius: 0;
      padding: 6px;
      margin: 6px auto;
      width: 90%;
      background-color: transparent;
    }

    .switch-label {
      margin-left: 5px;
      font-size: 12px;
      white-space: nowrap;
      font-family: 'PT Serif', serif;
    }

    .switch {
      position: relative;
      display: inline-block;
      width: 40px;
      height: 22px;
    }

    .slider {
      position: absolute;
      cursor: pointer;
      top: 0;
      left: 0;
      right: 0;
      bottom: 0;
      background-color: #555;
      border-radius: 0;
      transition: 0.2s;
    }

    .slider:before {
      position: absolute;
      content: "";
      height: 18px;
      width: 18px;
      left: 2px;
      bottom: 2px;
      background-color: white;
      border-radius: 0;
      transition: 0.2s;
    }

    input:checked + .slider {
      background-color: #B31b1b;
    }

    input:checked + .slider:before {
      transform: translateX(18px);
    }
  </style>
</head>
<body>
  <div class="intro">Peni Mod Menu<br>v11.4.1</div>

  <div class="mod-menu" id="mod-menu">
    <div class="mod-header" id="mod-header">
      <h2 class="mod-title">Tsum Tsum Peni MOD</h2>
    </div>
    
    <div class="scroll-container">
      <!-- コイン関連 -->
      <div class="switch-container">
        <span class="switch-label">コイン1億固定</span>
        <label class="switch">
          <input type="checkbox" id="coin1" onchange="coin1Fixed()">
          <span class="slider"></span>
        </label>
      </div>
      
      <div class="switch-container">
        <span class="switch-label">コイン2億固定</span>
        <label class="switch">
          <input type="checkbox" id="coin2" onchange="coin2Fixed()">
          <span class="slider"></span>
        </label>
      </div>
      
      <!-- プレイヤー関連 -->
      <div class="switch-container">
        <span class="switch-label">プレイヤーレベルMax</span>
        <label class="switch">
          <input type="checkbox" id="levelMax" onchange="playerLevelMax()">
          <span class="slider"></span>
        </label>
      </div>
      
      <!-- スコア/メダル -->
      <div class="switch-container">
        <span class="switch-label">スコア21億</span>
        <label class="switch">
          <input type="checkbox" id="maxScore" onchange="maxScore()">
          <span class="slider"></span>
        </label>
      </div>
      
      <div class="switch-container">
        <span class="switch-label">メダル100万倍</span>
        <label class="switch">
          <input type="checkbox" id="medal" onchange="medalMultiplier()">
          <span class="slider"></span>
        </label>
      </div>
      
      <!-- ツム関連 -->
      <div class="switch-container">
        <span class="switch-label">ツム獲得数5万固定</span>
        <label class="switch">
          <input type="checkbox" id="tsumCount" onchange="tsumCountFixed()">
          <span class="slider"></span>
        </label>
      </div>
      
      <!-- ゲームプレイ -->
      <div class="switch-container">
        <span class="switch-label">オートチェーン</span>
        <label class="switch">
          <input type="checkbox" id="autoChain" onchange="autoChain()">
          <span class="slider"></span>
        </label>
      </div>
      
      <div class="switch-container">
        <span class="switch-label">1つ消し</span>
        <label class="switch">
          <input type="checkbox" id="singleClear" onchange="singleClear()">
          <span class="slider"></span>
        </label>
      </div>
      
      <div class="switch-container">
        <span class="switch-label">全ツムオールチェーン</span>
        <label class="switch">
          <input type="checkbox" id="allChain" onchange="allChain()">
          <span class="slider"></span>
        </label>
      </div>
      
      <div class="switch-container">
        <span class="switch-label">ツム増量</span>
        <label class="switch">
          <input type="checkbox" id="tsumBoost" onchange="tsumBoost()">
          <span class="slider"></span>
        </label>
      </div>
      
      <!-- ガチャ関連 -->
      <div class="switch-container">
        <span class="switch-label">ガチャスキップ</span>
        <label class="switch">
          <input type="checkbox" id="gachaskip" onchange="gachaskip()">
          <span class="slider"></span>
        </label>
      </div>
      
      <div class="switch-container">
        <span class="switch-label">ピックアップガチャスキップ</span>
        <label class="switch">
          <input type="checkbox" id="pickupSkip" onchange="pickupGachaSkip()">
          <span class="slider"></span>
        </label>
      </div>
      
      <!-- セキュリティ回避 -->
      <div class="switch-container">
        <span class="switch-label">ルート化検出アラート削除</span>
        <label class="switch">
          <input type="checkbox" id="rootAlert" onchange="removeRootAlert()">
          <span class="slider"></span>
        </label>
      </div>
      
      <div class="switch-container">
        <span class="switch-label">LINE同意bypass</span>
        <label class="switch">
          <input type="checkbox" id="lineBypass" onchange="lineBypass()">
          <span class="slider"></span>
        </label>
      </div>
      
      <!-- リザルト関連 -->
      <div class="switch-container">
        <span class="switch-label">リザルトスキップ</span>
        <label class="switch">
          <input type="checkbox" id="resultSkip" onchange="resultSkip()">
          <span class="slider"></span>
        </label>
      </div>
      
      <div class="switch-container">
        <span class="switch-label">ツムレベルアップロック解除</span>
        <label class="switch">
          <input type="checkbox" id="levelUnlock" onchange="levelUnlock()">
          <span class="slider"></span>
        </label>
      </div>
      
      <div class="switch-container">
        <span class="switch-label">アイテム非表示</span>
        <label class="switch">
          <input type="checkbox" id="hideItems" onchange="hideItems()">
          <span class="slider"></span>
        </label>
      </div>
      
      <div class="switch-container">
        <span class="switch-label">試合結果スキップ</span>
        <label class="switch">
          <input type="checkbox" id="matchSkip" onchange="matchSkip()">
          <span class="slider"></span>
        </label>
      </div>
      
      <div class="switch-container">
        <span class="switch-label">即終了</span>
        <label class="switch">
          <input type="checkbox" id="instantEnd" onchange="instantEnd()">
          <span class="slider"></span>
        </label>
      </div>
      
      <div class="switch-container">
        <span class="switch-label">プレイ外速度×100</span>
        <label class="switch">
          <input type="checkbox" id="speed100x" onchange="speed100x()">
          <span class="slider"></span>
        </label>
      </div>
    </div>
  </div>

  <script>
    // 初期化処理
    try {
      authenticate();
      h5gg.require(7.9); 
      var h5frida = h5gg.loadPlugin("h5frida", "h5frida-15.1.24.dylib");
      if (!h5frida) throw "h5Fridaの読み込みに失敗！";
    } catch (error) {
      alert("Error loading h5gg or h5frida: " + error);
    }

    // コードパッチ関数
    function ActiveCodePatch(fpath, vaddr, bytes) {
      if (!h5frida.ActiveCodePatch(fpath, vaddr, bytes)) {
        var result = h5frida.ApplyCodePatch(fpath, vaddr, bytes);
        alert(fpath + ":0x" + vaddr.toString(16) + "-変更失敗!\n" + result);
        return false;
      }
      return true;
    }

    function DeactiveCodePatch(fpath, vaddr, bytes) {
      return h5frida.DeactiveCodePatch(fpath, vaddr, bytes);
    }

    // 各機能の実装
    function coin1Fixed() {
      const enabled = document.getElementById('coin1').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x103CD4, "4173A7F2");
        ActiveCodePatch("TsumTsum", 0x1040C0, "014099D2");
      } else {
        DeactiveCodePatch("TsumTsum", 0x103CD4, "4173A7F2");
        DeactiveCodePatch("TsumTsum", 0x1040C0, "014099D2");
      }
    }

    function coin2Fixed() {
      const enabled = document.getElementById('coin2').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x103A5C, "617DA152");
        ActiveCodePatch("TsumTsum", 0x103A60, "01409872");
      } else {
        DeactiveCodePatch("TsumTsum", 0x103A5C, "617DA152");
        DeactiveCodePatch("TsumTsum", 0x103A60, "01409872");
      }
    }

    function playerLevelMax() {
      const enabled = document.getElementById('levelMax').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x740308, "e17a020b");
      } else {
        DeactiveCodePatch("TsumTsum", 0x740308, "e17a020b");
      }
    }

    function maxScore() {
      const enabled = document.getElementById('maxScore').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x72D21c, "c0035fd6");
      } else {
        DeactiveCodePatch("TsumTsum", 0x72D21c, "c0035fd6");
      }
    }

    function medalMultiplier() {
      const enabled = document.getElementById('medal').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x2ea790, "617Da152");
        ActiveCodePatch("TsumTsum", 0x2ea794, "01409872");
      } else {
        DeactiveCodePatch("TsumTsum", 0x2ea790, "617Da152");
        DeactiveCodePatch("TsumTsum", 0x2ea794, "01409872");
      }
    }

    function tsumCountFixed() {
      const enabled = document.getElementById('tsumCount').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x732318, "014C9D52");
      } else {
        DeactiveCodePatch("TsumTsum", 0x732318, "014C9D52");
      }
    }

    function autoChain() {
      const enabled = document.getElementById('autoChain').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x779504, "1f2003d5");
      } else {
        DeactiveCodePatch("TsumTsum", 0x779504, "1f2003d5");
      }
    }

    function singleClear() {
      const enabled = document.getElementById('singleClear').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x73A71C, "016a9852");
      } else {
        DeactiveCodePatch("TsumTsum", 0x73A71C, "016a9852");
      }
    }

    function allChain() {
      const enabled = document.getElementById('allChain').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x779CFC, "c0035fd6");
      } else {
        DeactiveCodePatch("TsumTsum", 0x779CFC, "c0035fd6");
      }
    }

    function tsumBoost() {
      const enabled = document.getElementById('tsumBoost').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x734040, "29250071");
      } else {
        DeactiveCodePatch("TsumTsum", 0x734040, "29250071");
      }
    }

    function gachaskip() {
      const enabled = document.getElementById('gachaskip').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x7096C0, "c0035fd6");
      } else {
        DeactiveCodePatch("TsumTsum", 0x7096C0, "c0035fd6");
      }
    }

    function pickupGachaSkip() {
      const enabled = document.getElementById('pickupSkip').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x70FFBC, "c0035fd6");
      } else {
        DeactiveCodePatch("TsumTsum", 0x70FFBC, "c0035fd6");
      }
    }

    function removeRootAlert() {
      const enabled = document.getElementById('rootAlert').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x365f14, "c0035fd6");
      } else {
        DeactiveCodePatch("TsumTsum", 0x365f14, "c0035fd6");
      }
    }

    function lineBypass() {
      const enabled = document.getElementById('lineBypass').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x1251BBC, "02008052");
      } else {
        DeactiveCodePatch("TsumTsum", 0x1251BBC, "02008052");
      }
    }

    function resultSkip() {
      const enabled = document.getElementById('resultSkip').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x742100, "1f2003d5");
      } else {
        DeactiveCodePatch("TsumTsum", 0x742100, "1f2003d5");
      }
    }

    function levelUnlock() {
      const enabled = document.getElementById('levelUnlock').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x63c3cc, "c0035fd6");
      } else {
        DeactiveCodePatch("TsumTsum", 0x63c3cc, "c0035fd6");
      }
    }

    function hideItems() {
      const enabled = document.getElementById('hideItems').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x299054, "c0035fd6");
      } else {
        DeactiveCodePatch("TsumTsum", 0x299054, "c0035fd6");
      }
    }

    function matchSkip() {
      const enabled = document.getElementById('matchSkip').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x722D20, "340080D2");
      } else {
        DeactiveCodePatch("TsumTsum", 0x722D20, "340080D2");
      }
    }

    function instantEnd() {
      const enabled = document.getElementById('instantEnd').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x72be5c, "1f3003d5");
      } else {
        DeactiveCodePatch("TsumTsum", 0x72be5c, "1f3003d5");
      }
    }

    function speed100x() {
      const enabled = document.getElementById('speed100x').checked;
      if (enabled) {
        ActiveCodePatch("TsumTsum", 0x302940, "0090241E");
      } else {
        DeactiveCodePatch("TsumTsum", 0x302940, "0090241E");
      }
    }

    // ドラッグ機能
    const menu = document.getElementById('mod-menu');
    let isDragging = false;
    let offsetX = 0;
    let offsetY = 0;

    menu.addEventListener('mousedown', (e) => {
      isDragging = true;
      offsetX = e.clientX - menu.offsetLeft;
      offsetY = e.clientY - menu.offsetTop;
    });

    document.addEventListener('mousemove', (e) => {
      if (isDragging) {
        menu.style.left = `${e.clientX - offsetX}px`;
        menu.style.top = `${e.clientY - offsetY}px`;
      }
    });

    document.addEventListener('mouseup', () => {
      isDragging = false;
    });

    menu.addEventListener('touchstart', (e) => {
      isDragging = true;
      const touch = e.touches[0];
      offsetX = touch.clientX - menu.offsetLeft;
      offsetY = touch.clientY - menu.offsetTop;
    }, { passive: true });

    document.addEventListener('touchmove', (e) => {
      if (isDragging) {
        const touch = e.touches[0];
        menu.style.left = `${touch.clientX - offsetX}px`;
        menu.style.top = `${touch.clientY - offsetY}px`;
      }
    }, { passive: true });

    document.addEventListener('touchend', () => {
      isDragging = false;
    });
  </script>
</body>
</html>