Files
bd2/go/internal/client/app/web/index.html
T
Flechazo 6da2d9b89c feat(all): add server gameplay systems, one-step launcher installation, clearer update logs and shared file utilities
Server:
- Add castle and total war battles, IB battles, roguelike runs with castle and roguelike rankings, cafeteria and dating, life content, spine interactions and recordings, popularity rankings, gacha history and selection draws, map exploration, quest previews and completion, passes, rhythm events, quick battles, achievement progress, resource items, prestige illustrations and community notices.
- Report structured request errors from the gateway, validate avatars, and extend settlement evidence and existing domain handlers.
- Let bd2-host.sh deploy from a source directory or a prebuilt image and update the deployment docs and Docker ignore list.

Launcher:
- Prepare a new installation directly from the launcher (download, BepInEx, catalog, patch, plugins) through a shared preparation package also used by bd2client prepare.
- Launching and preparing now wait for a running background update instead of failing with "Another update operation is in progress"; manual update checks wait as well, and launch downloads no longer use the 12-second resource-policy timeout.
- Log what each update check found, every downloaded file, the server requirement, the game resource decision and installed plugins; skip warnings caused by closing the launcher.

Shared:
- Move file hashing and atomic replacement into common/util and use it from the build, release, launcher and server code.
2026-10-19 00:04:02 +08:00

210 lines
58 KiB
HTML
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
<!doctype html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width,initial-scale=1">
<meta name="theme-color" content="#e8decc">
<title>BD2 Launcher</title>
<link rel="icon" type="image/svg+xml" href="/icon.svg">
<link rel="alternate icon" href="/icon.ico">
<style>
:root{color-scheme:light;--paper:#eee7da;--ink:#382e26;--muted:#796c5d;--line:rgba(84,62,42,.18);--rust:#965437;--olive:#63704d;--bad:#9d4034;--ease:cubic-bezier(.22,1,.36,1);--serif:Georgia,'Songti SC','Noto Serif CJK SC',SimSun,serif;--sans:'Segoe UI','PingFang SC','Microsoft YaHei',sans-serif}
*{box-sizing:border-box}body{margin:0;background:#e7dcc7;color:var(--ink);font:14px/1.65 var(--sans);overflow-x:hidden}button,input{font:inherit}button{cursor:pointer}button:disabled{cursor:wait;opacity:.5}button,input,a{-webkit-tap-highlight-color:transparent}button:focus-visible,input:focus-visible,summary:focus-visible{outline:2px solid var(--rust);outline-offset:5px}[hidden]{display:none!important}::selection{background:#b9764c;color:#fff9ef}
.landscape{position:fixed;inset:0;z-index:-3;background:linear-gradient(130deg,#f1e9d9 0%,#e7d5b6 42%,#bc8665 100%);overflow:hidden}.landscape svg{position:absolute;width:100%;height:100%;transition:transform 2s var(--ease),opacity 1.6s;transform:scale(1.04);opacity:.87}.landscape:after{content:'';position:absolute;inset:0;background:linear-gradient(90deg,rgba(244,237,222,.8),rgba(240,228,207,.2) 65%,transparent),linear-gradient(0deg,rgba(73,48,31,.14),transparent 48%)}body[data-scene=server] .landscape svg{transform:scale(1.14) translateX(-2%)}body[data-scene=desk] .landscape svg{transform:scale(1.2) translateY(-3%);opacity:.27}body[data-scene=desk] .landscape:after{background:rgba(240,234,221,.55)}
.grain{position:fixed;inset:0;pointer-events:none;z-index:20;opacity:.038;background-image:url("data:image/svg+xml,%3Csvg viewBox='0 0 180 180' xmlns='http://www.w3.org/2000/svg'%3E%3Cfilter id='grain'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='.82' numOctaves='3' stitchTiles='stitch'/%3E%3C/filter%3E%3Cpath fill='%23000' filter='url(%23grain)' d='M0 0h180v180H0z'/%3E%3C/svg%3E")}.sunlight{position:fixed;inset:-40%;pointer-events:none;z-index:-2;background:radial-gradient(ellipse at 70% 23%,#fff7d777,transparent 38%);animation:drift 18s ease-in-out infinite alternate}
.topbar{height:94px;max-width:1440px;margin:auto;padding:0 58px;display:flex;align-items:center;justify-content:space-between;border-bottom:1px solid var(--line);gap:24px}.brand{display:flex;gap:13px;align-items:center;flex-shrink:0}.emblem{display:block;width:40px;height:40px;flex-shrink:0}.brand-name{font-size:13px;letter-spacing:.19em;line-height:1.4}.brand-name small{display:block;font-size:9px;letter-spacing:.28em;color:var(--muted);margin-top:4px}.text-btn{background:none;border:0;color:var(--muted);padding:8px 0;border-bottom:1px solid transparent}.text-btn:hover{color:var(--rust);border-bottom-color:var(--rust)}
main{max-width:1324px;margin:auto;padding:0 58px}.scene{position:relative}.intro-scene{min-height:calc(100svh - 178px);display:grid;grid-template-columns:1.1fr .9fr;align-items:center;gap:8%;padding:66px 0 82px}.eyebrow{font-size:10px;letter-spacing:.22em;text-transform:uppercase;display:flex;align-items:center;gap:12px;color:#81634c;margin-bottom:24px}.eyebrow:before{content:'';height:1px;width:32px;background:currentColor}h1,h2,h3,p{margin:0}h1{font:400 clamp(42px,4.8vw,68px)/1.28 var(--serif);letter-spacing:.035em}.lead{max-width:380px;font-size:14px;color:var(--muted);line-height:1.95;margin-top:26px}.intro-label{display:flex;gap:14px;align-items:center;margin-top:44px;font-size:11px;color:#8a7059}.intro-label i{height:1px;width:30px;background:#987759}.form-card{position:relative;background:linear-gradient(135deg,rgba(250,246,237,.89),rgba(238,225,203,.7));border:1px solid rgba(255,255,255,.6);box-shadow:0 24px 70px -35px #65472c77,inset 0 0 0 1px rgba(116,89,55,.035);backdrop-filter:blur(24px);border-radius:4px;padding:34px 32px}.card-number{font:italic 46px/1 var(--serif);color:#b2997e;opacity:.6;margin-bottom:30px}.form-card h2{font:400 23px var(--serif);margin-bottom:9px}.description{font-size:12px;line-height:1.8;color:var(--muted);margin-bottom:26px}code{font:11px/1.8 Consolas,monospace;overflow-wrap:anywhere}label.field-label{display:block;font-size:11px;margin-bottom:9px;color:#6f5c49}.input-row{display:flex;gap:8px}.input-row>.btn{flex-shrink:0}input[type=text]{width:100%;min-width:0;border:1px solid #aa927755;border-radius:3px;padding:13px 12px;background:#fffcf57d;color:var(--ink);outline:none;transition:background .2s,border-color .2s;font-size:12px}input[type=text]:focus{border-color:var(--rust);background:#fffaf0}.btn{border:1px solid #81664a55;border-radius:3px;padding:11px 18px;display:inline-flex;align-items:center;justify-content:center;gap:12px;min-height:43px;background:#fffcf533;color:var(--ink);transition:background .25s,box-shadow .25s,transform .25s;white-space:nowrap;font-size:12px}.btn:hover:not(:disabled){background:#fff9eb99;transform:translateY(-2px)}.btn.primary{background:#4b3a2c;color:#fff5e4;border-color:#4b3a2c}.btn.primary:hover:not(:disabled){background:#654932;box-shadow:0 6px 17px #4b3a2c24}.btn.rust{background:#985e40;color:#fff6e8;border-color:#985e40}.btn.rust:hover:not(:disabled){background:#ad6c49}.arrow{font-size:20px;font-weight:300;line-height:1}.wide{width:100%;justify-content:space-between;margin-top:28px;padding:14px 18px}.small-note{font-size:11px;color:#877460;margin-top:12px;line-height:1.8}.inline-result{font-size:11px;min-height:22px;margin-top:10px;color:var(--muted)}.inline-result.error{color:var(--bad)}.form-tools{display:flex;align-items:center;justify-content:space-between;margin-top:4px;gap:8px;font-size:11px}.server-back{margin-top:14px;text-align:center}.server-back .text-btn{font-size:11px}.bottom-bar{max-width:1324px;margin:auto;padding:0 58px 28px;display:flex;justify-content:space-between;align-items:center;gap:24px}.steps{display:flex;list-style:none;padding:0;margin:0;gap:26px;font-size:11px;color:#8f7d69}.steps li{display:flex;gap:8px;align-items:center}.steps .num{font:italic 14px var(--serif)}.steps li.active{color:#503b2b}.steps li.active:after{content:'';width:19px;height:1px;background:#86573b}.bottom-note{font-size:10px;color:#897963;letter-spacing:.04em}
.scene.is-entering .reveal{animation:reveal 1.3s var(--ease) both;animation-delay:calc(var(--i,0)*110ms)}.scene.is-leaving{animation:leave .55s cubic-bezier(.4,0,.6,1) both;pointer-events:none}.transition-veil{position:fixed;inset:0;background:linear-gradient(115deg,#eee4d4ed,#dfc7a8e8);z-index:30;pointer-events:none;opacity:0;backdrop-filter:blur(8px)}.transition-veil.play{animation:veil 1.25s ease-in-out both}.opening-curtain{position:fixed;inset:0;background:#e8decc;pointer-events:none;z-index:40;animation:opening 1.65s ease forwards}
.desk-scene{padding:46px 0 34px}.desk-header{display:flex;justify-content:space-between;align-items:end;gap:24px;margin-bottom:30px}.desk-header .eyebrow{margin-bottom:13px}.desk-header h1{font-size:42px}.desk-header p{margin-top:12px;font-size:12px;color:var(--muted)}.connection-chip{display:flex;align-items:center;gap:9px;font-size:11px;color:#74634f;border:1px solid var(--line);padding:8px 13px;border-radius:30px}.dot{width:6px;height:6px;border-radius:50%;background:#a99b85;display:inline-block;flex-shrink:0}.dot.good{background:var(--olive);box-shadow:0 0 0 4px #68744912}.dot.bad{background:var(--bad)}.desk-grid{display:grid;grid-template-columns:minmax(0,1fr) 298px;gap:24px}.main-panel{background:#f9f5ec94;border:1px solid #fff9;border-radius:4px;box-shadow:0 12px 50px -40px #5c412c55}.panel-section{padding:25px 28px;border-bottom:1px solid var(--line)}.panel-section:last-child{border-bottom:0}.section-title{display:flex;align-items:center;gap:11px;margin-bottom:22px}.section-title .index{font:italic 14px var(--serif);color:#a08569}.section-title h2{font-size:15px;font-weight:500}.section-title .end{margin-left:auto;font-size:10px;color:var(--muted)}.setting-row{display:flex;align-items:center;justify-content:space-between;gap:20px;margin-top:18px}.setting-name{font-size:10px;color:var(--muted);margin-bottom:4px}.setting-value{font-size:12px;overflow-wrap:anywhere}.setting-row>div{min-width:0}.setting-row .text-btn{font-size:11px;flex-shrink:0;color:var(--rust)}.route-options{display:grid;grid-template-columns:repeat(3,minmax(0,1fr));gap:10px}.route{position:relative;cursor:pointer}.route input{position:absolute;opacity:0;inset:0;width:100%;height:100%;margin:0}.route-content{display:block;position:relative;pointer-events:none;min-height:139px;padding:15px 14px;border:1px solid var(--line);border-radius:3px;transition:.25s;background:#f8f3e83d}.route-content .route-top{display:flex;align-items:center;justify-content:space-between;margin-bottom:16px}.route-code{font:10px var(--serif);letter-spacing:.08em;color:#98826b}.radio-dot{width:11px;height:11px;border-radius:50%;border:1px solid #aa9680;display:block}.route-content strong{font-size:12px;font-weight:500;display:block;margin-bottom:5px}.route-content small{font-size:10px;line-height:1.75;display:block;color:var(--muted)}.route input:checked+.route-content{border-color:#9e7551;background:#b9986920;box-shadow:inset 0 0 0 1px #9e755118}.route input:checked+.route-content .radio-dot{background:#916c4a;border:3px solid #e8d9c3;box-shadow:0 0 0 1px #916c4a}.route input:focus-visible+.route-content{outline:2px solid var(--rust);outline-offset:4px}.route input:disabled+.route-content{opacity:.55}.route-actions{display:flex;align-items:center;justify-content:space-between;gap:10px;margin-top:18px}.route-actions .text-btn{font-size:11px}.route-hint{font-size:10px;color:#927d64;margin-top:13px}.policy{font:11px/1.9 Consolas,monospace;white-space:pre-wrap;overflow-wrap:anywhere;background:#dfd2bc50;border-left:2px solid #a3835e;padding:13px;margin-top:16px}.prepare-note{font-size:11px;color:var(--muted);margin:-8px 0 19px;line-height:1.8}.prepare-actions{display:flex;gap:10px;flex-wrap:wrap}.prepare-actions .btn{flex:1}.status-panel{align-self:start;padding:25px 23px;background:#dfd1ba66;border:1px solid #9875501c;border-radius:4px}.status-title{display:flex;align-items:center;justify-content:space-between;margin-bottom:6px}.status-title h2{font:400 19px var(--serif)}.status-title span{font-size:9px;color:#927d65;letter-spacing:.1em}.check{display:flex;align-items:center;justify-content:space-between;padding:14px 0;border-bottom:1px solid var(--line);font-size:11px;gap:8px}.check span:last-child{color:#948471;font-size:10px}.check span.ok{color:var(--olive)}.check span.warn{color:var(--bad)}.status-foot{font-size:10px;color:#8d7a63;margin-top:14px;line-height:1.8}.log-wrap{border-top:1px solid var(--line);margin-top:24px;padding-top:19px}.log-heading{font-size:10px;color:#8d745b;display:flex;align-items:center;justify-content:space-between;margin-bottom:12px}.log{font-size:11px;color:#7e6c56;line-height:1.8;overflow-wrap:anywhere;min-height:65px}.log strong{display:block;color:var(--ink);font-size:12px;font-weight:500;margin-bottom:5px}.history{margin-top:14px;border-top:1px solid var(--line);padding-top:12px;font-size:10px;color:#806e59}.history summary{cursor:pointer}.history ol{list-style:none;padding:0;margin:10px 0 0;max-height:180px;overflow:auto}.history li{padding:7px 0;border-top:1px solid #a487651a;overflow-wrap:anywhere}.history time{display:block;color:#9a876f;font-size:9px}.history li.error{color:var(--bad)}.unsaved{font-size:10px;color:var(--rust);margin-top:12px}.desk-footer{display:flex;justify-content:space-between;gap:20px;margin-top:24px;color:#8a765e;font-size:10px}
.desk-actions{display:flex;align-items:center;gap:10px;flex-wrap:wrap;justify-content:flex-end}.desk-actions .btn{min-height:38px;padding:8px 16px}.local-resource{margin-top:14px;padding:14px;border:1px solid var(--line);background:#f8f3e83d;border-radius:3px}.local-resource[hidden]{display:none}.local-resource .small-note{margin:8px 0 0}
.update-box{display:grid;gap:4px;margin-top:12px;padding:10px 12px;border:1px solid #c9ac8288;border-radius:3px;background:#fff8ec80;font-size:12px}.update-box span{white-space:pre-line;max-height:120px;overflow:auto;color:#6d5a47}.update-box .text-btn{justify-self:start}.toast{position:fixed;bottom:28px;left:50%;transform:translate(-50%,18px);max-width:min(590px,calc(100% - 32px));width:max-content;padding:13px 21px;background:#483a2e;color:#fff4e0;box-shadow:0 10px 40px #483a2e26;border:1px solid #c9ac82;border-radius:3px;font-size:12px;opacity:0;pointer-events:none;transition:.35s var(--ease);z-index:70}.toast.show{opacity:1;transform:translate(-50%,0)}.toast.error{background:#793e30;color:#fff0e3}dialog{width:min(490px,calc(100% - 32px));padding:30px;border:1px solid #fff9;border-radius:5px;background:#f0e7d7;color:var(--ink);box-shadow:0 30px 140px #37271955}dialog::backdrop{background:#40322266;backdrop-filter:blur(9px)}dialog[open]{animation:reveal .55s var(--ease)}.dialog-head{display:flex;align-items:center;justify-content:space-between;margin-bottom:25px}.dialog-head h2{font:24px var(--serif)}.dialog-close{background:none;border:0;font-size:23px;color:var(--muted);padding:0 7px}.dialog-actions{display:flex;justify-content:flex-end;margin-top:20px}.quit-scene{min-height:65svh;display:flex;flex-direction:column;justify-content:center;align-items:center;text-align:center}.quit-scene h1{font-size:44px}.quit-scene p{color:var(--muted);margin-top:20px;font-size:13px}
@keyframes reveal{from{opacity:0;filter:blur(10px);transform:translateY(24px) scale(.986)}to{opacity:1;filter:blur(0);transform:none}}@keyframes leave{to{opacity:0;filter:blur(8px);transform:translateY(-15px) scale(1.014)}}@keyframes veil{0%,100%{opacity:0}45%,58%{opacity:1}}@keyframes opening{0%,15%{opacity:1}100%{opacity:0}}@keyframes drift{to{transform:translate(-4%,3%) scale(1.05)}}
@media(min-width:1500px){.intro-scene{gap:13%}.form-card{padding:40px}.intro-scene h1{font-size:72px}}@media(max-width:1050px){.topbar{padding:0 30px}main,.bottom-bar{padding-left:30px;padding-right:30px}.intro-scene{gap:5%}.form-card{padding:27px 23px}.desk-grid{grid-template-columns:minmax(0,1fr) 250px;gap:16px}.panel-section{padding:23px 20px}.status-panel{padding:23px 18px}.route-content{padding:12px 10px}}@media(max-width:760px){.topbar{height:77px;padding:0 22px}main,.bottom-bar{padding-left:22px;padding-right:22px}.intro-scene{grid-template-columns:1fr;gap:32px;padding:42px 0;min-height:auto}.intro-scene h1{font-size:43px}.eyebrow{margin-bottom:17px}.lead{margin-top:18px;max-width:100%}.intro-label{display:none}.form-card{padding:25px}.card-number{position:absolute;right:25px;top:25px;font-size:31px}.form-card h2{padding-right:45px}.bottom-bar{align-items:start;flex-direction:column;gap:15px}.steps{gap:21px}.desk-scene{padding-top:31px}.desk-header{align-items:start}.desk-header h1{font-size:34px}.connection-chip{font-size:10px;padding:6px 10px;margin-top:4px}.desk-grid{grid-template-columns:1fr}.status-panel{display:grid;grid-template-columns:1fr 1fr;gap:0 30px}.status-title{grid-column:1/-1}.log-wrap{margin-top:10px;border-top:0}.status-foot{margin-bottom:14px}.desk-footer{flex-direction:column;gap:7px}.bottom-note{font-size:9px}.landscape svg{width:180%;left:-60%}.desk-header p{max-width:240px}.route-content{min-height:145px}}@media(max-width:400px){main,.bottom-bar{padding-left:16px;padding-right:16px}.form-card{padding:23px 18px}.route-options{grid-template-columns:1fr}.route-content{min-height:0;padding:12px 14px}.route-content .route-top{float:right;margin:0 0 10px 20px;gap:12px}.route-content small{max-width:90%}.status-panel{display:block}.desk-header{flex-direction:column;gap:14px}.panel-section{padding:22px 16px}.btn{padding-left:13px;padding-right:13px}.steps{gap:15px}.route-actions{align-items:stretch}.prepare-actions{flex-direction:column}}
@media(prefers-reduced-motion:reduce){*,*:before,*:after{animation:none!important;transition:none!important;scroll-behavior:auto!important}.opening-curtain{display:none}}
.proxy-select{width:100%;padding:12px 14px;border:1px solid var(--line);border-radius:3px;background:#f8f3e8;color:var(--ink);font:inherit}#proxyURL{width:100%}/* Window chrome belongs to the page; keep scrolling without a visible gutter. */
html,body{scrollbar-width:none}html::-webkit-scrollbar,body::-webkit-scrollbar{display:none}
.topbar{--wails-draggable:drag;position:sticky;top:0;z-index:50;max-width:none;margin:0;padding-right:164px;user-select:none;background:linear-gradient(90deg,#f1e9d9d9,#e7d5b6b3);backdrop-filter:blur(18px)}
.window-controls{--wails-draggable:no-drag;position:absolute;right:8px;top:8px;display:flex;gap:2px}
.window-control{--wails-draggable:no-drag;width:44px;height:36px;padding:0;border:0;border-radius:4px;display:grid;place-items:center;background:transparent;color:var(--ink);cursor:default;transition:background .15s,color .15s}
.window-control:hover{background:#8064481c}.window-control.window-close:hover{background:#b84b3a;color:white}.window-control:focus-visible{outline:2px solid var(--rust);outline-offset:-3px}
.window-control svg{width:12px;height:12px;pointer-events:none;fill:none;stroke:currentColor;stroke-width:1.3}
@media(max-width:1050px){.topbar{padding-right:164px}}@media(max-width:760px){.topbar{padding-right:152px}.brand-name{font-size:11px;letter-spacing:.12em}.brand-name small{font-size:8px}.window-control{width:40px}}
.lang-select{--wails-draggable:no-drag;flex-shrink:0;border:1px solid var(--line);border-radius:3px;background:#fffcf533;color:var(--muted);font:11px var(--sans);padding:5px 8px;cursor:pointer}.lang-select:hover:not(:disabled){color:var(--rust);border-color:#96543766}.lang-select:focus-visible{outline:2px solid var(--rust);outline-offset:3px}
html:lang(ja){--sans:'Segoe UI','Yu Gothic UI',Meiryo,sans-serif;--serif:Georgia,'Yu Mincho','Noto Serif CJK JP',serif}html:lang(ko){--sans:'Segoe UI','Malgun Gothic','Apple SD Gothic Neo',sans-serif;--serif:Georgia,Batang,'Noto Serif CJK KR',serif}html:lang(zh-TW){--sans:'Segoe UI','Microsoft JhengHei','PingFang TC',sans-serif;--serif:Georgia,'Noto Serif CJK TC',PMingLiU,serif}
</style>
</head>
<body data-scene="directory">
<div class="landscape" aria-hidden="true">
<svg viewBox="0 0 1600 1000" preserveAspectRatio="xMidYMid slice" xmlns="http://www.w3.org/2000/svg"><defs><linearGradient id="sky" x2="0" y2="1"><stop stop-color="#f3e6c9"/><stop offset=".7" stop-color="#dab88e"/><stop offset="1" stop-color="#b98560"/></linearGradient><linearGradient id="mesa" x2="0.2" y2="1"><stop stop-color="#b48360"/><stop offset="1" stop-color="#8f624b"/></linearGradient><linearGradient id="sand" x2=".6" y2="1"><stop stop-color="#b8946e"/><stop offset="1" stop-color="#674b39"/></linearGradient><filter id="soft"><feGaussianBlur stdDeviation="18"/></filter></defs><path fill="url(#sky)" d="M0 0h1600v1000H0z"/><circle cx="1150" cy="270" r="91" fill="#fff4ce" opacity=".4" filter="url(#soft)"/><circle cx="1150" cy="270" r="68" fill="#fff0c7" opacity=".8"/><path d="M0 640 240 590 370 610 520 558 670 580 820 510 950 560 1120 492 1280 560 1420 482 1600 530V1000H0Z" fill="#bea17f" opacity=".6"/><path d="m835 710 60-133 43-18 17-104 32-8 17-45 130-2 18 48 32 6 15 112 35 14 36 114 58 38 212 18V1000H790Z" fill="url(#mesa)" opacity=".65"/><path d="m1004 400 15 162 24 39-12 110 75 112 18-203-23-111 33-109z" fill="#d3a079" opacity=".38"/><path d="m1280 760 81-113 24-160 47-12 13-59 122 3 14 67 19 18v496h-320Z" fill="#9a6b4f" opacity=".6"/><path d="M0 746Q260 652 525 746T1030 775 1600 724V1000H0Z" fill="#c8aa80"/><path d="M0 869Q300 687 660 860T1300 814 1600 830V1000H0Z" fill="url(#sand)" opacity=".65"/><path d="M860 1000q185-97 375-124t365-13v137Z" fill="#826045" opacity=".7"/><path d="M870 998q146-128 235-165t69-90" fill="none" stroke="#e1c397" stroke-width="3" opacity=".24"/></svg>
</div>
<div class="sunlight" aria-hidden="true"></div><div class="grain" aria-hidden="true"></div><div class="opening-curtain" aria-hidden="true"></div><div id="veil" class="transition-veil" aria-hidden="true"></div>
<header class="topbar"><div class="brand"><img class="emblem" src="/icon.svg" width="40" height="40" alt=""><div class="brand-name"><span data-i18n="launcher.brand.title"></span><small data-i18n="launcher.brand.subtitle"></small></div></div><select class="lang-select" id="language" data-i18n-attr="aria-label:launcher.language;title:launcher.language"><option value="en_us" lang="en">English</option><option value="ko_kr" lang="ko">한국어</option><option value="ja_jp" lang="ja">日本語</option><option value="zh_tw" lang="zh-TW">繁體中文</option><option value="zh_cn" lang="zh-CN">简体中文</option></select><div class="window-controls" role="group" data-i18n-attr="aria-label:launcher.window.controls"><button class="window-control" id="windowMinimise" data-i18n-attr="aria-label:launcher.window.minimize;title:launcher.window.minimize"><svg viewBox="0 0 12 12" aria-hidden="true"><path d="M1 9h10"/></svg></button><button class="window-control" id="windowMaximise" data-i18n-attr="aria-label:launcher.window.maximize;title:launcher.window.maximize"><svg viewBox="0 0 12 12" aria-hidden="true"><rect x="1.5" y="1.5" width="9" height="9"/></svg></button><button class="window-control window-close" id="windowClose" data-i18n-attr="aria-label:launcher.window.close;title:launcher.window.close"><svg viewBox="0 0 12 12" aria-hidden="true"><path d="m1.5 1.5 9 9m0-9-9 9"/></svg></button></div></header>
<main>
<section class="scene intro-scene is-entering" id="directoryScene" aria-labelledby="directoryTitle">
<div><div class="eyebrow reveal" style="--i:1" data-i18n="launcher.directory.step"></div><h1 class="reveal" style="--i:2" id="directoryTitle" tabindex="-1" data-i18n="launcher.directory.heading"></h1><p class="lead reveal" style="--i:3" data-i18n="launcher.directory.lead"></p><div class="intro-label reveal" style="--i:4"><i></i><span data-i18n="launcher.directory.label"></span></div></div>
<div class="form-card reveal" style="--i:4"><div class="card-number" aria-hidden="true">01</div><h2 data-i18n="launcher.directory.title"></h2><p class="description" id="directoryDescription" data-i18n="launcher.directory.description" data-i18n-code="BrownDust II.exe"></p><div id="directoryHome"><div id="directoryFields"><label class="field-label" for="gameDir" data-i18n="launcher.directory.field"></label><div class="input-row"><input id="gameDir" type="text" value="" data-i18n-attr="placeholder:launcher.directory.placeholder" autocomplete="off" spellcheck="false"><button class="btn" id="browse" data-i18n="launcher.browse"></button></div><div class="form-tools"><span id="directoryHint" data-i18n="launcher.directory.hint"></span><button class="text-btn" id="inspect" data-i18n="launcher.directory.inspect"></button></div><p class="inline-result" id="directoryResult" role="status"></p></div></div><button class="btn primary wide" id="directoryNext"><span data-i18n="launcher.directory.next"></span><span class="arrow" aria-hidden="true">→</span></button></div>
</section>
<section class="scene intro-scene" id="serverScene" hidden aria-labelledby="serverTitle">
<div><div class="eyebrow reveal" style="--i:1" data-i18n="launcher.server.step"></div><h1 class="reveal" style="--i:2" id="serverTitle" tabindex="-1" data-i18n="launcher.server.heading"></h1><p class="lead reveal" style="--i:3" data-i18n="launcher.server.lead"></p><div class="intro-label reveal" style="--i:4"><i></i><span data-i18n="launcher.server.label"></span></div></div>
<div class="form-card reveal" style="--i:4"><div class="card-number" aria-hidden="true">02</div><h2 data-i18n="launcher.server.title"></h2><p class="description" data-i18n="launcher.server.description"></p><div id="serverHome"><div id="serverFields"><label class="field-label" for="origin" data-i18n="launcher.server.field"></label><input id="origin" type="text" value="" placeholder="https://play.example.com" autocomplete="url" spellcheck="false" aria-describedby="originHint"><p class="small-note" id="originHint" data-i18n="launcher.server.hint" data-i18n-code="http://192.168.1.8:8080|/game/"></p><p class="inline-result" id="serverResult" role="status"></p></div></div><button class="btn primary wide" id="serverNext"><span data-i18n="launcher.server.next"></span><span class="arrow" aria-hidden="true">→</span></button><div class="server-back"><button class="text-btn" id="serverBack" data-i18n="launcher.server.back"></button></div></div>
</section>
<section class="scene desk-scene" id="deskScene" hidden aria-labelledby="deskTitle">
<header class="desk-header reveal" style="--i:0"><div><div class="eyebrow" data-i18n="launcher.desk.step"></div><h1 id="deskTitle" tabindex="-1" data-i18n="launcher.title"></h1><p data-i18n="launcher.desk.subtitle"></p></div><div class="desk-actions"><div class="connection-chip"><span class="dot" id="pulse"></span><span id="overallStatus"></span></div><button class="btn primary" id="launch"><span data-i18n="launcher.launch"></span> <span aria-hidden="true">▶</span></button></div></header>
<div class="desk-grid"><div class="main-panel reveal" style="--i:1">
<section class="panel-section"><div class="section-title"><span class="index">01</span><h2 data-i18n="launcher.connection.title"></h2><span class="end" data-i18n="launcher.connection.editable"></span></div><div class="setting-row"><div><div class="setting-name" data-i18n="launcher.connection.directory"></div><div class="setting-value" id="directorySummary"></div></div><button class="text-btn" id="editDirectory" data-i18n="launcher.connection.change_directory"></button></div><div class="setting-row"><div><div class="setting-name" data-i18n="launcher.server.title"></div><div class="setting-value" id="serverSummary"></div></div><button class="text-btn" id="editServer" data-i18n="launcher.connection.change_server"></button></div><div class="setting-row"><div><div class="setting-name" data-i18n="launcher.connection.proxy"></div><div class="setting-value" id="proxySummary"></div></div><button class="text-btn" id="editProxy" data-i18n="launcher.connection.set_proxy"></button></div></section>
<section class="panel-section"><div class="section-title"><span class="index">02</span><h2 data-i18n="launcher.resources.title"></h2><span class="end">CDN</span></div><div class="route-options" role="radiogroup" data-i18n-attr="aria-label:launcher.resources.group">
<label class="route"><input type="radio" name="cdn" value="official" checked><span class="route-content"><span class="route-top"><span class="route-code" data-i18n="launcher.resources.official.code"></span><span class="radio-dot"></span></span><strong data-i18n="launcher.resources.official.name"></strong><small data-i18n="launcher.resources.official.description"></small></span></label>
<label class="route"><input type="radio" name="cdn" value="local"><span class="route-content"><span class="route-top"><span class="route-code" data-i18n="launcher.resources.local.code"></span><span class="radio-dot"></span></span><strong data-i18n="launcher.resources.local.name"></strong><small data-i18n="launcher.resources.local.description"></small></span></label>
<label class="route"><input type="radio" name="cdn" value="server"><span class="route-content"><span class="route-top"><span class="route-code" data-i18n="launcher.resources.server.code"></span><span class="radio-dot"></span></span><strong data-i18n="launcher.resources.server.name"></strong><small data-i18n="launcher.resources.server.description"></small></span></label>
</div><div class="local-resource" id="localResource" hidden><label class="field-label" for="localResourceDir" data-i18n="launcher.resources.local_root"></label><div class="input-row"><input id="localResourceDir" type="text" value="" data-i18n-attr="placeholder:launcher.resources.local_placeholder" autocomplete="off" spellcheck="false"><button class="btn" id="browseResources" data-i18n="launcher.browse"></button></div><p class="small-note" data-i18n="launcher.resources.local_note" data-i18n-code="ServerData|GameData"></p></div><p class="route-hint" id="routeHint"></p><div class="route-actions"><button class="text-btn" id="checkResources" data-i18n="launcher.resources.verify"></button><button class="btn" id="save" data-i18n="launcher.save"></button></div><p class="unsaved" id="dirtyNotice" data-i18n="launcher.unsaved"></p><div class="policy" id="policy" role="status" hidden></div></section>
<section class="panel-section"><div class="section-title"><span class="index">03</span><h2 data-i18n="launcher.prepare.title"></h2></div><p class="prepare-note" data-i18n="launcher.prepare.note" data-i18n-code="resources.assets.bak"></p><div class="prepare-actions"><button class="btn primary" id="prepare"><span data-i18n="launcher.prepare.run"></span> <span aria-hidden="true">↗</span></button><button class="btn rust" id="patch"><span data-i18n="launcher.prepare.patch"></span> <span aria-hidden="true">↗</span></button><button class="btn primary" id="install"><span data-i18n="launcher.prepare.install"></span> <span aria-hidden="true">↗</span></button></div></section>
</div><aside class="status-panel reveal" style="--i:3" data-i18n-attr="aria-label:launcher.status.label"><div class="status-title"><h2 data-i18n="launcher.status.title"></h2><span data-i18n="launcher.status.tagline"></span></div><div><div class="check"><span data-i18n="launcher.status.executable"></span><span id="sExe"></span></div><div class="check"><span data-i18n="launcher.status.assets"></span><span id="sAssets"></span></div><div class="check"><span>BepInEx</span><span id="sBep"></span></div><div class="check"><span data-i18n="launcher.status.config"></span><span id="sConfig"></span></div><p class="status-foot"><span data-i18n="launcher.status.foot"></span><br><span data-i18n="launcher.status.client_version"></span><code id="clientReleaseVersion"></code><br><span data-i18n="launcher.status.game_version"></span><code id="gameReleaseVersion"></code><br><span data-i18n="launcher.status.log_path"></span><code id="persistentLogPath"></code></p><button class="text-btn" style="font-size:11px" id="refresh" data-i18n="launcher.status.refresh"></button><div class="update-box" id="updateBox" hidden><strong id="updateTitle"></strong><span id="updateNotes"></span><button class="text-btn" style="font-size:11px" id="updateAction" hidden></button></div></div><div class="log-wrap"><div class="log-heading"><span data-i18n="launcher.log.title"></span><time id="logTime">—</time></div><div class="log" id="log" role="status"><strong data-i18n="launcher.log.idle"></strong><span data-i18n="launcher.log.idle_hint"></span></div><details class="history"><summary data-i18n="launcher.log.history"></summary><ol id="historyList"></ol></details></div></aside></div>
<footer class="desk-footer reveal" style="--i:4"><span>BD2 LAUNCHER <span aria-hidden="true">/</span> <span data-i18n="launcher.footer.local_only"></span></span><span data-i18n="launcher.footer.no_secrets"></span></footer>
</section>
<section class="scene quit-scene" id="quitScene" hidden aria-labelledby="quitTitle"><div class="eyebrow reveal">LAUNCHER</div><h1 class="reveal" id="quitTitle" tabindex="-1" data-i18n="launcher.quit.title"></h1><p class="reveal" data-i18n="launcher.quit.hint"></p></section>
</main>
<footer class="bottom-bar" id="journey"><ol class="steps" data-i18n-attr="aria-label:launcher.steps.label"><li data-step="directory" class="active" aria-current="step"><span class="num">01</span><span data-i18n="launcher.steps.directory"></span></li><li data-step="server"><span class="num">02</span><span data-i18n="launcher.steps.server"></span></li><li data-step="desk"><span class="num">03</span><span data-i18n="launcher.title"></span></li></ol><span class="bottom-note">BROWN DUST II · GAME LAUNCHER</span></footer>
<div id="proxyHome" hidden><div id="proxyFields"><label class="field-label" for="proxyMode" data-i18n="launcher.proxy.mode"></label><select id="proxyMode" class="proxy-select"><option value="direct" data-i18n="launcher.proxy.direct"></option><option value="manual" data-i18n="launcher.proxy.manual"></option></select><div id="proxyAddressField" hidden style="margin-top:18px"><label class="field-label" for="proxyURL" data-i18n="launcher.proxy.address"></label><input id="proxyURL" type="text" placeholder="http://127.0.0.1:7890" autocomplete="off" spellcheck="false"><p class="small-note" data-i18n="launcher.proxy.address_hint"></p></div><p class="small-note" data-i18n="launcher.proxy.apply_hint"></p><p class="small-note" data-i18n="launcher.proxy.https_hint"></p><p id="proxyResult" class="inline-result" role="status"></p></div></div>
<dialog id="editor" aria-labelledby="editorTitle"><div class="dialog-head"><h2 id="editorTitle" data-i18n="launcher.editor.title"></h2><button class="dialog-close" id="closeEditor" data-i18n-attr="aria-label:launcher.editor.close">×</button></div><div id="editorContent"></div><p class="small-note" data-i18n="launcher.editor.note"></p><div class="dialog-actions"><button class="btn primary" id="doneEditor" data-i18n="launcher.editor.done"></button></div></dialog>
<div class="toast" id="toast" role="status" aria-live="polite"></div>
<noscript><p style="padding:20px">Enable JavaScript to use the BD2 Launcher. / 请启用 JavaScript 以使用 BD2 启动器。</p></noscript>
<script src="/text.js"></script>
<script>
(async ()=>{
'use strict';
let HOST_PLATFORM='',INITIAL_CDN='official',AUTO_OPEN=false;
const $=id=>document.getElementById(id);
const reduced=window.matchMedia('(prefers-reduced-motion: reduce)');
const LOCALES=['en_us','ko_kr','ja_jp','zh_tw','zh_cn'],HTML_LANG={en_us:'en',ko_kr:'ko',ja_jp:'ja',zh_tw:'zh-TW',zh_cn:'zh-CN'},LOCALE_KEY='bd2.locale',translations={};
let locale='en_us',lastUpdate=null;
const staleRender = Symbol('stale render'), renderPasses = new Map(), renderNodes = new WeakMap();
function beginRender(id) { const store = typeof id === 'string' ? renderPasses : renderNodes, pass = {id, locale, store}; store.set(id, pass); return pass; }
function rendered(value, pass) { if (locale !== pass.locale || pass.store.get(pass.id) !== pass) throw staleRender; return value; }
const {Component}=window.BD2Text;
const own=(table,key)=>Boolean(table)&&Object.prototype.hasOwnProperty.call(table,key)&&typeof table[key]==='string';
function lookup(key){const selected=translations[locale],fallback=translations.en_us;return own(selected,key)?selected[key]:own(fallback,key)?fallback[key]:key}
Component.configure({lookup,locale:()=>locale,formatURL:'/text/format'});
const t=key=>lookup(key)??key;
const dynamicText = (key, ...args) => Component.translatable(key, ...args.map(value => value && typeof value.getString === 'function' ? value : value == null ? '' : String(value))).getString();
const textOf=value=>value&&typeof value.getString==='function'?value:Component.literal(value??'');
async function rich(element,component){const language=locale,text=await component.getString();if(language===locale){element.textContent=text;element.style.whiteSpace='pre-line'}}
async function applyStatic(){await Promise.all(Array.from(document.querySelectorAll('[data-i18n]')).map(async e=>await rich(e,Component.translatable(e.dataset.i18n,...(e.dataset.i18nCode?e.dataset.i18nCode.split('|'):[])))));document.querySelectorAll('[data-i18n-attr]').forEach(e=>e.dataset.i18nAttr.split(';').forEach(pair=>{const at=pair.indexOf(':');if(at>0)e.setAttribute(pair.slice(0,at).trim(),t(pair.slice(at+1).trim()))}))}
const live=new Set();
async function put(target,value){const e=typeof target==='string'?$(target):target,component=textOf(value),pass={};e.bd2Text=component;e.bd2Pass=pass;live.add(e);const text=await component.getString();if(e.bd2Pass===pass)e.textContent=text}
function detectLocale(){let saved='';try{saved=localStorage.getItem(LOCALE_KEY)||''}catch{}if(LOCALES.includes(saved))return saved;const tags=navigator.languages&&navigator.languages.length?navigator.languages:[navigator.language||''];for(const tag of tags){const l=String(tag).toLowerCase();if(/^ko(-|$)/.test(l))return'ko_kr';if(/^ja(-|$)/.test(l))return'ja_jp';if(/^zh(-|$)/.test(l))return/^zh-(tw|hk|mo)(-|$)/.test(l)||/-hant(-|$)/.test(l)?'zh_tw':'zh_cn';if(/^en(-|$)/.test(l))return'en_us'}return'en_us'}
async function loadTranslations(){await Promise.all(LOCALES.map(async l=>{try{const r=await fetch(`lang/${l}.json`);if(r.ok)translations[l]=await r.json()}catch{}}))}
async function setLocale(next,save){locale=LOCALES.includes(next)?next:'en_us';if(save)try{localStorage.setItem(LOCALE_KEY,locale)}catch{}document.documentElement.lang=HTML_LANG[locale];document.title=t('launcher.title');$('language').value=locale;await applyStatic();await Promise.all([...live].map(e=>{if(e.isConnected)return put(e,e.bd2Text);live.delete(e)}));await sync();if(lastUpdate)await renderUpdates(lastUpdate)}
let scene='directory',busy=false,transitioning=false,toastTimer,editorKind=null,savedSignature=null;
const status={executable:null,resources:null,bepinex:null,config:null};
function payload(){const mode=document.querySelector('input[name="cdn"]:checked').value;return{game_directory:$('gameDir').value.trim(),server_origin:$('origin').value.trim(),cdn_mode:mode,local_resource_directory:mode==='local'?$('localResourceDir').value.trim():'',proxy_url:$('proxyMode').value==='manual'?$('proxyURL').value.trim():''}}
function signature(){return JSON.stringify({...payload(),proxy_mode:$('proxyMode').value})}
const backendKeys={'Update check completed':'backend.update_checked','Launcher is restarting to finish the update':'backend.launcher_restarting','update service is unavailable':'backend.update_unavailable','Another update operation is in progress':'backend.update_busy','No launcher update is available':'backend.no_launcher_update','The launcher update has not finished downloading':'backend.launcher_update_incomplete','The launcher is updating; start the game after it finishes':'backend.launcher_updating','The game is running; its plugins update after it exits':'backend.game_running_plugins','The server is updating; try again after it finishes':'backend.server_maintenance','Selection cancelled':'backend.selection_cancelled','Game client found':'backend.game_found','Installation directory selected':'backend.directory_selected','Local resource directory found':'backend.local_resources_found','Game directory is valid':'backend.directory_valid','The client will use the release-locked official CDN':'backend.official_cdn','Local resources verified':'backend.local_verified','Server resource policy verified':'backend.server_policy_verified','Connection settings saved':'backend.settings_saved','Client prepared':'backend.prepared','Client entry point patched; the original backup was retained':'backend.patched','Client patch is already complete; no asset file was rewritten':'backend.patch_current','BD2 client plugins installed or updated':'backend.plugins_installed','BD2 client plugins are already up to date; no DLL was rewritten':'backend.plugins_current','Brown Dust II started':'backend.game_started','Brown Dust II is already running':'backend.game_running','Client tool exited':'backend.tool_exited'};
const PLUGINS_REJECTED=/^Server (\S+) no longer accepts these plugins: (.+)\. Update the plugins in the launcher first$/;
const pluginList=list=>({getString:async ()=>(await Promise.all(list.split(', ').map(async item=>{const m=/^(.+) (\S+) \(needs (\S+)\)$/.exec(item);return m?await dynamicText('backend.plugin_requirement',m[1],m[2],m[3]):item}))).join(t('common.list_separator'))});
const GAME_MISMATCH=/^Server game version (\S+) does not match client game version (\S+)$/;
function backendText(message){if(!message)return null;message=String(message);if(Object.prototype.hasOwnProperty.call(backendKeys,message))return Component.translatable(backendKeys[message]);const game=GAME_MISMATCH.exec(message);if(game)return Component.translatable('backend.game_mismatch',game[1],game[2]);const m=PLUGINS_REJECTED.exec(message);return m?Component.translatable('backend.plugins_rejected',m[1],pluginList(m[2])):Component.literal(message)}
class Problem extends Error{constructor(component){super('Launcher operation failed');this.component=component}}
const fail=(key,...args)=>new Problem(Component.translatable(key,...args));
const problemText=error=>error instanceof Problem?error.component:backendText(error&&error.message||String(error))||Component.translatable('launcher.operation.failed');
const nativeMethods={browse:'Browse',browseResources:'BrowseResources',inspect:'Inspect',resources:'Resources',save:'Save',patch:'Patch',install:'Install',prepare:'Prepare',launch:'Launch'};
function bridge(){const bindings=window.go&&window.go.app&&window.go.app.Studio;if(!bindings)throw fail('launcher.error.bridge');return bindings}
async function api(operation,body={}){let data;try{data=await bridge()[nativeMethods[operation]](body)}catch(error){throw new Problem(problemText(error))}if(!data||!data.ok)throw new Problem(backendText(data&&data.message)||Component.translatable('launcher.operation.failed'));data.text=backendText(data.message);return data}
async function show(message,error=false){const result=Component.translatable(error?'launcher.operation.failed':'launcher.operation.completed'),body=message?textOf(message):result;clearTimeout(toastTimer);const toast=$('toast');await put(toast,body);toast.className='toast show'+(error?' error':'');toastTimer=setTimeout(()=>toast.className='toast',5200);const title=document.createElement('strong'),desc=document.createElement('span');await put(title,result);await put(desc,body);$('log').replaceChildren(title,desc);const now=new Date(),time=now.toLocaleTimeString(HTML_LANG[locale],{hour:'2-digit',minute:'2-digit',second:'2-digit'});$('logTime').textContent=time;const row=document.createElement('li'),stamp=document.createElement('time'),entry=document.createElement('span');if(error)row.className='error';stamp.dateTime=now.toISOString();stamp.textContent=time;await put(entry,body);row.append(stamp,entry);$('historyList').prepend(row);while($('historyList').children.length>20)$('historyList').lastElementChild.remove()}
async function mark(id,value,yes='launcher.status.ready',no='launcher.status.not_found'){const e=$(id);await put(e,Component.translatable(value===null?'launcher.status.waiting':value?yes:no));e.className=value===null?'':value?'ok':'warn'}
async function renderStatus(){await mark('sExe',status.executable);await mark('sAssets',status.resources);await mark('sBep',status.bepinex,'launcher.status.installed','launcher.status.manual_install');await mark('sConfig',status.config,'launcher.status.written','launcher.status.not_written');const checked=status.executable!==null&&status.resources!==null;const ready=status.executable&&status.resources;$('pulse').className='dot'+(checked?(ready?' good':' bad'):'');await put('overallStatus',Component.translatable(checked?(ready?'launcher.status.files_ready':'launcher.status.files_attention'):'launcher.status.waiting'));if(savedSignature&&signature()!==savedSignature){await put('sConfig',Component.translatable('launcher.status.unsaved'));$('sConfig').className='warn'}}
async function sync(){const p=payload(),manual=$('proxyMode').value==='manual';await put('directorySummary',p.game_directory||Component.translatable('launcher.connection.not_selected'));await put('serverSummary',p.server_origin||Component.translatable('launcher.connection.not_entered'));await put('proxySummary',manual?(p.proxy_url||Component.translatable('launcher.proxy.manual_missing')):Component.translatable('launcher.proxy.direct'));$('proxyAddressField').hidden=!manual;$('localResource').hidden=p.cdn_mode!=='local';await put('routeHint',Component.translatable('launcher.resources.hint.'+p.cdn_mode));$('dirtyNotice').hidden=signature()===savedSignature;await renderStatus()}
async function applyStatus(s){if(!s)return;if(s.game_directory)$('gameDir').value=s.game_directory;for(const key of Object.keys(status))status[key]=Boolean(s[key]);await sync();const found=status.executable&&status.resources;await put('directoryResult',Component.translatable(found?'launcher.directory.found':'launcher.directory.incomplete'));$('directoryResult').className='inline-result'+(found?'':' error')}
async function invalidate(directory=false){if(directory){for(const key of Object.keys(status))status[key]=null;await put('directoryResult',Component.translatable('launcher.directory.changed'))}$('policy').hidden=true;await sync()}
function requireDirectory(){if(!payload().game_directory){$('gameDir').focus();throw fail('launcher.error.directory_required')}}
async function requireOrigin(){const value=$('origin').value.trim();let u;try{u=new URL(value)}catch{throw fail('launcher.error.origin_invalid','http://127.0.0.1:8080')}if(!['http:','https:'].includes(u.protocol)||u.username||u.password||u.search||u.hash||(u.pathname!=='/'&&u.pathname!==''))throw fail('launcher.error.origin_shape');const loopback=['localhost','127.0.0.1','[::1]'].includes(u.hostname.toLowerCase());if(u.protocol!=='https:'&&!loopback)throw fail('launcher.error.origin_https');$('origin').value=value.replace(/\/$/,'');await put('serverResult','');await sync()}
function requireResources(){const p=payload();if(p.cdn_mode==='local'&&!p.local_resource_directory){$('localResourceDir').focus();throw fail('launcher.error.resources_required')}}
async function requireProxy(){if($('proxyMode').value!=='manual')return;const value=$('proxyURL').value.trim();let u;try{u=new URL(value)}catch{}if(!u||u.protocol!=='http:'||u.username||u.password||u.search||u.hash||u.pathname!=='/'||!/^http:\/\/(?:\[[^\]]+\]|[^\s/:?#@]+):[0-9]+$/.test(value)||Number(value.slice(value.lastIndexOf(':')+1))<1||Number(value.slice(value.lastIndexOf(':')+1))>65535){const message=Component.translatable('launcher.error.proxy_invalid','http://127.0.0.1:7890');await put('proxyResult',message);$('proxyResult').className='inline-result error';$('proxyURL').focus();throw new Problem(message)}$('proxyURL').value=value;await put('proxyResult','');await sync()}
function setBusy(value){busy=value;document.querySelectorAll('button:not(.window-control),input,select').forEach(e=>{e.disabled=value});document.body.setAttribute('aria-busy',String(value))}
async function action(id,fn){if(busy||transitioning)return;const b=$(id),old=b.innerHTML;setBusy(true);b.textContent=t('launcher.operation.wait');try{await fn()}catch(e){const message=problemText(e);await show(message,true);if(scene==='directory'||editorKind==='directory'){await put('directoryResult',message);$('directoryResult').className='inline-result error'}if(scene==='server'||editorKind==='server'){await put('serverResult',message);$('serverResult').className='inline-result error'}}finally{b.innerHTML=old;setBusy(false)}}
const delay=ms=>new Promise(resolve=>setTimeout(resolve,ms));
async function navigateScene(next){if(transitioning||scene===next)return;transitioning=true;const old=$(scene+'Scene'),target=$(next+'Scene');if(!reduced.matches){old.classList.add('is-leaving');$('veil').classList.add('play');await delay(570)}old.hidden=true;old.classList.remove('is-leaving','is-entering');scene=next;document.body.dataset.scene=next;target.hidden=false;target.classList.add('is-entering');$('journey').hidden=next==='desk'||next==='quit';document.querySelectorAll('[data-step]').forEach(e=>{const active=e.dataset.step===next;e.classList.toggle('active',active);if(active)e.setAttribute('aria-current','step');else e.removeAttribute('aria-current')});window.scrollTo({top:0,behavior:'instant'});$(next==='directory'?'directoryTitle':next==='server'?'serverTitle':next==='desk'?'deskTitle':'quitTitle').focus({preventScroll:true});if(!reduced.matches)await delay(680);$('veil').classList.remove('play');transitioning=false}
async function inspect(){requireDirectory();const r=await api('inspect',payload());await applyStatus(r.data);await show(r.text);return r}
async function openEditor(kind){if(busy||transitioning)return;editorKind=kind;await put('editorTitle',Component.translatable(kind==='directory'?'launcher.editor.directory':kind==='server'?'launcher.editor.server':'launcher.proxy.title'));$('editorContent').append($(kind+'Fields'));$('editor').showModal();$(kind==='directory'?'gameDir':kind==='server'?'origin':'proxyMode').focus()}
function closeEditor(){if(busy)return;$('editor').close()}
$('editor').addEventListener('close',async ()=>{if(editorKind)$(editorKind+'Home').append($(editorKind+'Fields'));editorKind=null;await sync()});
$('editor').addEventListener('cancel',e=>{if(busy)e.preventDefault()});
$('closeEditor').onclick=closeEditor;
$('doneEditor').onclick=async ()=>{try{if(editorKind==='server')await requireOrigin();else if(editorKind==='proxy')await requireProxy();else requireDirectory();closeEditor()}catch(e){await show(problemText(e),true)}};
$('editProxy').onclick=async ()=>await openEditor('proxy');$('proxyMode').addEventListener('change',async ()=>{await put('proxyResult','');await invalidate()});$('proxyURL').addEventListener('input',async ()=>{await put('proxyResult','');await invalidate()});
$('editDirectory').onclick=async ()=>await openEditor('directory');$('editServer').onclick=async ()=>await openEditor('server');
$('gameDir').addEventListener('input',async ()=>await invalidate(true));$('origin').addEventListener('input',async ()=>{await put('serverResult','');await invalidate()});$('localResourceDir').addEventListener('input',async ()=>await invalidate());document.querySelectorAll('input[name="cdn"]').forEach(e=>e.addEventListener('change',async ()=>await invalidate()));
$('browse').onclick=async ()=>await action('browse',async()=>{const previous=payload().game_directory;const r=await api('browse',{...payload(),dialog_title:t('launcher.dialog.game_directory')});if(r.data){await applyStatus(r.data);if(payload().game_directory!==previous)$('policy').hidden=true}await show(r.text)});
$('browseResources').onclick=async ()=>await action('browseResources',async()=>{const r=await api('browseResources',{...payload(),dialog_title:t('launcher.dialog.resource_directory')});if(r.data){$('localResourceDir').value=r.data.local_directory||'';await invalidate()}await show(r.text)});
$('inspect').onclick=async ()=>await action('inspect',inspect);$('refresh').onclick=async ()=>await action('refresh',inspect);
$('directoryNext').onclick=async ()=>await action('directoryNext',async()=>{requireDirectory();await sync();await navigateScene('server')});
$('serverBack').onclick=async ()=>{if(!busy)await navigateScene('directory')};
$('serverNext').onclick=async ()=>await action('serverNext',async()=>{await requireOrigin();await sync();await navigateScene('desk')});
$('checkResources').onclick=async ()=>await action('checkResources',async()=>{requireDirectory();await requireOrigin();requireResources();await requireProxy();const r=await api('resources',payload()),p=r.data||{},local=payload().local_resource_directory,v=value=>value||t('launcher.resources.missing');$('policy').hidden=false;await put('policy',{getString:()=>p.mode==='official'?`${t('launcher.resources.official.code')} · ${t('launcher.resources.policy_official')}`:p.mode==='local'?`${t('launcher.resources.local.code')} · ${p.local_directory||local}\nServerData · ${v(p.server_data_url)}\nGameData · ${v(p.game_data_url)}`:`${t('launcher.resources.server.code')} · ${t('launcher.resources.policy_server')}\nServerData · ${v(p.server_data_url)}\nGameData · ${v(p.game_data_url)}\nBundle · ${v(p.bundle_version)}\nGameData · ${v(p.game_data_version)}`});await show(r.text)});
async function saved(){savedSignature=signature();status.config=true;await sync()}
$('save').onclick=async ()=>await action('save',async()=>{requireDirectory();await requireOrigin();requireResources();await requireProxy();const r=await api('save',payload());await saved();await show(r.text)});
$('prepare').onclick=async ()=>await action('prepare',async()=>{requireDirectory();await requireOrigin();requireResources();await requireProxy();const r=await api('prepare',payload());await applyStatus(r.data);await saved();await show(r.text)});
$('patch').onclick=async ()=>await action('patch',async()=>{requireDirectory();await requireOrigin();requireResources();await requireProxy();const r=await api('patch',payload());await saved();await show(r.text)});
$('install').onclick=async ()=>await action('install',async()=>{requireDirectory();await requireOrigin();requireResources();await requireProxy();const r=await api('install',payload());status.bepinex=true;await saved();await show(r.text)});
$('launch').onclick=async ()=>await action('launch',async()=>{requireDirectory();await requireOrigin();requireResources();await requireProxy();const r=await api('launch',payload());await saved();await show(r.text)});
$('language').addEventListener('change',async e=>await setLocale(e.target.value,true));
$('windowMinimise').onclick=()=>window.runtime?.WindowMinimise();
$('windowMaximise').onclick=()=>window.runtime?.WindowToggleMaximise();
document.querySelector('.topbar').ondblclick=e=>{if(!e.target.closest('.window-controls,.lang-select'))window.runtime?.WindowToggleMaximise()};
$('windowClose').onclick=async ()=>{clearTimeout(toastTimer);try{bridge().Quit().catch(async error=>await show(problemText(error),true))}catch(error){await show(problemText(error),true)}};
$('gameDir').addEventListener('keydown',e=>{if(e.key==='Enter'){e.preventDefault();(editorKind?$('inspect'):$('directoryNext')).click()}});$('origin').addEventListener('keydown',e=>{if(e.key==='Enter'){e.preventDefault();(editorKind?$('doneEditor'):$('serverNext')).click()}});
async function initialize(){setBusy(true);try{const initial=await bridge().Initialize();HOST_PLATFORM=initial.platform;INITIAL_CDN=initial.cdn_mode;AUTO_OPEN=initial.auto_open;$('gameDir').value=initial.game_directory||'';$('origin').value=initial.server_origin||'http://127.0.0.1:8080';$('localResourceDir').value=initial.local_resource_directory||'';$('proxyURL').value=initial.proxy_url||'';$('proxyMode').value=initial.proxy_url?'manual':'direct';$('clientReleaseVersion').textContent=initial.client_version||'';$('gameReleaseVersion').textContent=initial.game_version||'';$('persistentLogPath').textContent=initial.log_path||'';const initialRadio=document.querySelector(`input[name="cdn"][value="${CSS.escape(INITIAL_CDN)}"]`);if(initialRadio)initialRadio.checked=true;if(HOST_PLATFORM==='darwin'){const description=$('directoryDescription');$('gameDir').dataset.i18nAttr='placeholder:launcher.directory.placeholder_mac';description.dataset.i18n='launcher.directory.description_mac';description.dataset.i18nCode='BrownDust II.app';await applyStatic()}await sync();if(AUTO_OPEN){await inspect();await saved();await navigateScene('desk')}}catch(error){await show(problemText(error),true)}finally{setBusy(false)}}
const updateNotes=notes=>!notes?'':typeof notes==='string'?notes:notes[locale]||notes.en_us||Object.values(notes).find(Boolean)||'';
function formatBytes(bytes){const mb=bytes>=1048576,value=bytes/(mb?1048576:1024);try{return new Intl.NumberFormat(HTML_LANG[locale],{style:'unit',unit:mb?'megabyte':'kilobyte',maximumFractionDigits:1}).format(value)}catch{return value.toFixed(1)+(mb?' MB':' KB')}}
function formatDate(value){const date=new Date(value+'T00:00:00Z');if(!/^\d{4}-\d{2}-\d{2}$/.test(value)||isNaN(date))return value;try{return date.toLocaleDateString(HTML_LANG[locale],{year:'numeric',month:'long',day:'numeric',timeZone:'UTC'})}catch{return value}}
const lines=(...items)=>items.filter(Boolean).join('\n');
const updateMeta=async item=>[item.date?await dynamicText('update.released',formatDate(String(item.date))):'',item.bytes>0?await dynamicText('update.size',formatBytes(item.bytes)):''].filter(Boolean).join(' · ');
async function renderUpdates(u) {
const renderPass = beginRender('launcher-updates');
try {
if (!u) return;
lastUpdate = u;
const message = u.message && u.message.key
? rendered(await dynamicText(u.message.key, ...(u.message.args || [])), renderPass) : '';
let head = '', body = '', label = '', act = '';
if (u.busy) {
const pct = u.total ? Math.floor(u.done * 100 / u.total) : 0;
head = t(u.busy === 'checking' || u.busy === 'preparing' ? 'update.' + u.busy : 'update.busy');
body = u.busy === 'checking' || u.busy === 'preparing' ? '' : u.busy === 'downloading' ? rendered(await dynamicText('update.downloading', pct), renderPass)
: t(u.busy === 'restarting' ? 'update.restarting' : u.busy === 'checking' ? 'update.checking'
: u.busy === 'preparing' ? 'update.preparing' : 'update.installing');
} else if (u.launcher) {
head = rendered(await dynamicText('update.launcher.available', u.launcher.version), renderPass);
body = lines(message, rendered(await updateMeta(u.launcher), renderPass), updateNotes(u.launcher.notes));
label = t(u.launcher.ready ? 'update.launcher.restart' : 'update.launcher.download');
act = u.launcher.ready ? 'apply' : 'check';
} else if (u.game) {
head = rendered(await dynamicText('update.game.available', u.game.version), renderPass);
body = lines(t('update.game.exit_hint'), u.error, ...(u.waiting || []));
label = t('update.game.update'); act = 'check';
} else if (u.plugins) {
head = rendered(await dynamicText('update.plugins.available', u.plugins.version), renderPass);
body = lines(message, rendered(await updateMeta(u.plugins), renderPass), updateNotes(u.plugins.notes));
label = t('update.plugins.update'); act = 'check';
} else if (u.waiting && u.waiting.length) {
head = t('update.plugins.ready'); body = lines(message, t('update.plugins.ready_hint'), ...u.waiting);
} else if (u.error) {
head = t('update.failed'); body = lines(message, u.error); label = t('update.retry'); act = 'check';
} else if (message) head = message;
$('updateBox').hidden = !head;
$('updateTitle').textContent = head; $('updateNotes').textContent = body;
const button = $('updateAction');
button.hidden = !act; button.textContent = label; button.dataset.act = act;
} catch (error) { if (error !== staleRender) throw error; }
}
async function updateAction(){const act=$('updateAction').dataset.act;const method=act==='apply'?'ApplyLauncherUpdate':'CheckUpdates';let data;try{data=await bridge()[method]()}catch(error){throw new Problem(problemText(error))}await show(backendText(data&&data.message))}
$('updateAction').onclick=async ()=>await action('updateAction',updateAction);
async function pollUpdates(){try{await renderUpdates(await bridge().UpdateStatus())}catch(error){await show(Component.literal(error.message||String(error)),true)}}
async function start(){await loadTranslations();await setLocale(detectLocale(),false);setInterval(pollUpdates,4000);setTimeout(pollUpdates,1500);await initialize()}
window.addEventListener('unhandledrejection',event=>{console.error(event.reason);const box=$('toast');box.textContent=String(event.reason&&event.reason.message||event.reason);box.className='toast show error';clearTimeout(toastTimer);toastTimer=setTimeout(()=>box.className='toast',5200)});
await start();
})();
</script>
</body>
</html>