Files
06web/src/main/webapp/index.html
T
Dark98 e57315b785 feat(web): add Pause in Background option, TeaVM reflection filtering, and HUD drawImage guards
Improve webclient stability, background resource usage, and script reflection compatibility across desktop and mobile browsers.

### Web Client Features & Fixes
- `index.html` & `RSApplet.java`
  - Added a **Pause in Background** (`#opt-pause-bg`) option under **Display & Graphics** persisted in `localStorage` (`2006scape_web_options.pauseInBackground`) and synced live via `window.scapePauseInBackground`.
  - Added `visibilitychange` Web Audio suspend/resume handling in `index.html` and `isPausedInBackground()` loop throttling in `RSApplet.run()` (resetting timing buffers on resume to avoid tick bursts).
- `DesktopHooks.java`
  - Added `naturalWidth > 0` guards to `jsDrawModernMinimap` and `jsDrawModernChat` to prevent `InvalidStateError` on `drawImage` when HUD images are still loading or broken.

### TeaVM Script Reflection
- `WebReflectionSupplier.java`
  - Added `hasUnscriptableParam(...)` to exclude methods referencing `java.util.function.*`, `java.lang.Thread*`, `java.io.*`, or `java.awt.*` from TeaVM reflection metadata.
2026-12-02 17:20:27 +00:00

914 lines
40 KiB
HTML

<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no, viewport-fit=cover, interactive-widget=overlays-content" />
<meta name="apple-mobile-web-app-capable" content="yes" />
<meta name="apple-mobile-web-app-status-bar-style" content="black-translucent" />
<meta name="apple-mobile-web-app-title" content="2006Scape" />
<meta name="mobile-web-app-capable" content="yes" />
<meta name="theme-color" content="#000000" />
<title>RuneScape - Free Multiplayer Online Game</title>
<link rel="manifest" href="manifest.webmanifest" />
<link rel="apple-touch-icon" href="navbar_mainmenu.gif" />
<link rel="icon" href="navbar_mainmenu.gif" type="image/gif" />
<style>
html, body {
margin: 0;
padding: env(safe-area-inset-top, 0px) env(safe-area-inset-right, 0px) env(safe-area-inset-bottom, 0px) env(safe-area-inset-left, 0px);
box-sizing: border-box;
width: 100%;
max-width: 100vw;
height: 100%;
background: #000000;
color: #d9b44a;
font-family: Arial, Helvetica, sans-serif;
overflow: hidden;
display: flex;
flex-direction: column;
align-items: center;
justify-content: flex-start;
}
#rs-footer {
margin-top: 8px;
font-size: 11px;
color: #777777;
text-align: center;
line-height: 1.5;
user-select: none;
z-index: 10;
}
#rs-footer .legal {
margin-top: 4px;
font-size: 10px;
color: #666666;
}
#rs-footer.floating .legal {
display: none;
}
#rs-footer a, #rs-footer label {
color: #c8a856;
text-decoration: underline;
cursor: pointer;
margin: 0 6px;
}
#rs-footer a:hover, #rs-footer label:hover {
color: #ffffff;
}
#rs-footer.floating {
position: fixed;
top: 4px;
left: 50%;
transform: translateX(-50%);
margin-top: 0;
background: rgba(0, 0, 0, 0.7);
padding: 2px 8px;
border: 1px solid #2b2418;
border-radius: 2px;
white-space: nowrap;
}
#rs-navbar.visible ~ #rs-footer.floating {
top: 29px;
}
@media (max-width: 764px) {
#rs-navbar.visible {
display: none !important;
}
#rs-navbar.visible ~ #rs-footer.floating {
top: 4px;
}
}
#rs-frame {
display: flex;
flex-direction: column;
align-items: center;
box-shadow: 0 0 0 1px #2a2318;
}
#rs-navbar {
width: 765px;
max-width: 100%;
height: 25px;
overflow: hidden;
background: url('navbar.gif') repeat-x;
display: none;
justify-content: center;
user-select: none;
z-index: 9;
}
#rs-navbar.visible {
display: flex;
}
#rs-navbar-inner {
position: relative;
width: 765px;
height: 25px;
flex-shrink: 0;
font-family: Arial, sans-serif;
font-size: 11px;
}
.rs-nav-item {
position: absolute;
top: 0;
height: 25px;
display: flex;
align-items: center;
gap: 4px;
color: #ffffff;
text-decoration: underline;
cursor: pointer;
}
.rs-nav-item:hover {
color: #c0c0c0;
}
.rs-nav-item img {
display: block;
}
#stage {
position: relative;
flex: 1;
min-height: 0;
width: 100%;
overflow: hidden;
display: flex;
align-items: center;
justify-content: center;
background: #000;
}
@media (max-width: 764px) {
#stage {
align-items: flex-start;
padding-top: 4px;
}
}
#canvas-wrap {
position: relative;
display: inline-block;
line-height: 0;
}
#gl-canvas {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
z-index: 1;
pointer-events: none;
}
#game-canvas {
position: relative;
z-index: 2;
display: block;
image-rendering: auto;
touch-action: none;
outline: none;
max-width: 100%;
max-height: 100%;
background: transparent;
}
#loading-overlay {
position: absolute;
inset: 0;
background: rgba(10, 10, 12, 0.92);
display: flex;
flex-direction: column;
align-items: center;
justify-content: center;
gap: 12px;
z-index: 20;
}
#loading-overlay.hidden {
display: none;
}
.progress-track {
width: 320px;
height: 14px;
background: #1d1a16;
border: 1px solid #4e4230;
border-radius: 3px;
overflow: hidden;
}
.progress-fill {
width: 0%;
height: 100%;
background: linear-gradient(90deg, #8b1e1e, #d4a442);
transition: width 0.15s ease;
}
#loading-text {
font-size: 13px;
color: #d6c59c;
}
#options-modal {
position: fixed;
inset: 0;
background: rgba(0, 0, 0, 0.72);
display: none;
align-items: center;
justify-content: center;
z-index: 200;
padding: 12px;
}
#options-modal.open {
display: flex;
}
.options-card {
width: 100%;
max-width: 380px;
max-height: calc(100vh - 24px);
max-height: calc(100dvh - 24px);
display: flex;
flex-direction: column;
background: #1c1813;
border: 2px solid #5c4c34;
border-radius: 6px;
box-shadow: 0 12px 32px rgba(0, 0, 0, 0.8);
color: #e6d5a8;
font-size: 13px;
overflow: hidden;
}
.options-header {
display: flex;
align-items: center;
justify-content: space-between;
flex-shrink: 0;
padding: 10px 14px;
background: #2b2318;
border-bottom: 1px solid #4e4230;
font-weight: 700;
color: #f3c65f;
}
.options-body {
padding: 12px 14px;
display: flex;
flex-direction: column;
gap: 10px;
flex: 1;
min-height: 0;
overflow-y: auto;
}
.opt-group {
border: 1px solid #3c3428;
border-radius: 4px;
padding: 8px 10px;
display: flex;
flex-direction: column;
gap: 8px;
background: #14110d;
}
.opt-group-title {
font-size: 11px;
text-transform: uppercase;
letter-spacing: 0.6px;
color: #c9a75c;
font-weight: 700;
}
.opt-row {
display: flex;
align-items: center;
justify-content: space-between;
gap: 8px;
}
.opt-row input[type="text"], .opt-row input[type="password"], .opt-row input[type="number"], .opt-row select {
flex: 1;
max-width: 190px;
background: #231e17;
color: #f5ebd1;
border: 1px solid #4e4230;
border-radius: 3px;
padding: 5px 8px;
font-size: 14px;
}
@media (max-width: 640px) {
.opt-row input[type="text"], .opt-row input[type="password"], .opt-row input[type="number"], .opt-row select {
font-size: 16px;
}
}
.options-footer {
display: flex;
justify-content: flex-end;
flex-shrink: 0;
gap: 8px;
padding: 10px 14px;
background: #171410;
border-top: 1px solid #3c3428;
}
.options-footer button, .options-header button {
background: #2b251c;
color: #e6d5a8;
border: 1px solid #4e4230;
border-radius: 4px;
padding: 5px 12px;
cursor: pointer;
font-size: 12px;
}
.options-footer button.primary {
background: #7c2319;
border-color: #b54534;
color: #fff3d6;
font-weight: 600;
}
</style>
</head>
<body>
<div id="stage">
<div id="rs-frame">
<div id="rs-navbar">
<div id="rs-navbar-inner">
<img src="navbar_jagex.gif" alt="Jagex" style="position:absolute;left:5px;top:0;" />
<a id="nav-mainmenu" class="rs-nav-item" style="left:126px;" target="_blank" rel="noopener">
<img src="navbar_mainmenu.gif" alt="" /><span>Main Menu</span>
</a>
<a id="nav-worldselect" class="rs-nav-item" style="left:250px;" href="javascript:void(0)">
<img src="navbar_mainmenu.gif" alt="" /><span>World Select</span>
</a>
<a id="nav-worldmap" class="rs-nav-item" style="left:387px;" target="_blank" rel="noopener">
<img src="navbar_worldmap.gif" alt="" /><span>World Map</span>
</a>
<a id="nav-manual" class="rs-nav-item" style="left:520px;" target="_blank" rel="noopener">
<img src="navbar_manual.gif" alt="" /><span>Manual</span>
</a>
<a id="nav-rules" class="rs-nav-item" style="left:636px;" target="_blank" rel="noopener">
<img src="navbar_rules.gif" alt="" /><span>Rules &amp; Security</span>
</a>
</div>
</div>
<div id="canvas-wrap">
<canvas id="gl-canvas" width="765" height="503"></canvas>
<canvas id="game-canvas" width="765" height="503" tabindex="0"></canvas>
</div>
<div id="rs-footer">
<div>
<a id="btn-options" href="javascript:void(0)" title="Configure auto-login, server, and graphics">Options</a>
|
<label for="script-upload" title="Import .script / .bsh / .java into browser storage">Import Script</label>
<input id="script-upload" type="file" accept=".script,.bsh,.java" multiple style="display:none" />
</div>
<div class="legal">
RuneScape is a registered trademark of Jagex Limited in the United Kingdom and other countries.<br />
Copyright &copy; 1999 - 2006 Jagex Ltd.
</div>
</div>
</div>
<div id="loading-overlay">
<div style="font-size:18px;font-weight:700;color:#f3c65f;">2006Scape Web Client</div>
<div class="progress-track"><div id="progress-fill" class="progress-fill"></div></div>
<div id="loading-text">Initializing TeaVM runtime...</div>
</div>
</div>
<input id="mobile-kb-input" type="text" autocomplete="off" autocorrect="off" autocapitalize="off" spellcheck="false"
style="position:fixed;left:8px;top:44px;width:2px;height:2px;font-size:16px;opacity:0.01;border:0;padding:0;margin:0;background:transparent;color:transparent;caret-color:transparent;z-index:100;" />
<div id="options-modal">
<form class="options-card" onsubmit="return false;">
<div class="options-header">
<span>Client Options</span>
<button id="opt-close" type="button">&times;</button>
</div>
<div class="options-body">
<div class="opt-group">
<div class="opt-group-title">Auto-Login</div>
<label class="opt-row">
<span>Enable Auto-Login</span>
<input id="opt-autologin" type="checkbox" />
</label>
<label class="opt-row">
<span>Username</span>
<input id="opt-username" type="text" autocomplete="username" placeholder="Username" />
</label>
<label class="opt-row">
<span>Password</span>
<input id="opt-password" type="password" autocomplete="current-password" placeholder="Password" />
</label>
</div>
<div class="opt-group">
<div class="opt-group-title">Server &amp; World</div>
<label class="opt-row">
<span>Server Host</span>
<input id="opt-server" type="text" placeholder="192.168.1.88" />
</label>
<label class="opt-row">
<span>World</span>
<input id="opt-world" type="number" min="1" max="99" value="1" />
</label>
</div>
<div class="opt-group">
<div class="opt-group-title">Display &amp; Graphics</div>
<label class="opt-row">
<span>317HD (WebGL2)</span>
<input id="opt-hd" type="checkbox" />
</label>
<label class="opt-row">
<span>Display Mode</span>
<select id="opt-mode">
<option value="0">Fixed</option>
<option value="1">Resizable</option>
<option value="2">Fullscreen</option>
</select>
</label>
<label class="opt-row">
<span>Show Classic Navbar</span>
<input id="opt-navbar" type="checkbox" />
</label>
<label class="opt-row">
<span>Pause in Background</span>
<input id="opt-pause-bg" type="checkbox" />
</label>
</div>
</div>
<div class="options-footer">
<button id="opt-cancel" type="button">Cancel</button>
<button id="opt-save" type="button">Save</button>
<button id="opt-save-reload" type="button" class="primary">Save &amp; Reload</button>
</div>
</form>
</div>
<!-- Web Audio + Cache Preloader (must run synchronously before client.js main()) -->
<script src="libfluidsynth-2.3.0.js"></script>
<script src="js-synthesizer.min.js"></script>
<script>
window.scapeWebAudio = {
ctx: null,
midiGain: 0.7,
synth: null,
synthNode: null,
synthLoading: null,
synthAssetsLoading: null,
synthReady: false,
pendingMidi: null,
midiPlaySeq: 0,
ensureCtx() {
if (!this.ctx) {
const AudioCtx = window.AudioContext || window.webkitAudioContext;
if (AudioCtx) {
try {
this.ctx = new AudioCtx({ latencyHint: 'interactive' });
} catch (_) {
this.ctx = new AudioCtx();
}
}
}
if (this.ctx && this.ctx.state === 'suspended') {
this.ctx.resume().then(() => {
if (this.pendingMidi && this.synthReady && this.ctx && this.ctx.state === 'running') {
const pending = this.pendingMidi;
this.pendingMidi = null;
this.playMidi(pending, this.midiGain, this.midiLoop);
}
}).catch(() => {});
}
return this.ctx;
},
preloadFluidSynthAssets() {
if (this.synthAssetsLoading) return this.synthAssetsLoading;
if (typeof JSSynth === 'undefined') return Promise.resolve(null);
this.synthAssetsLoading = (async () => {
const [, sfBuf] = await Promise.all([
JSSynth.waitForReady(),
fetch('TimGM6mb.sf2').then(resp => {
if (!resp || !resp.ok) throw new Error('Failed to fetch TimGM6mb.sf2');
return resp.arrayBuffer();
})
]);
return sfBuf;
})().catch(e => {
console.warn('FluidSynth preload error:', e);
this.synthAssetsLoading = null;
return null;
});
return this.synthAssetsLoading;
},
ensureFluidSynth() {
if (this.synthReady) return Promise.resolve(this.synth);
if (this.synthLoading) return this.synthLoading;
const ctx = this.ensureCtx();
if (!ctx || typeof JSSynth === 'undefined') return Promise.resolve(null);
this.synthLoading = (async () => {
try {
const sfBuf = await this.preloadFluidSynthAssets();
if (!sfBuf) throw new Error('SoundFont unavailable');
const s = new JSSynth.Synthesizer();
s.init(ctx.sampleRate);
await s.loadSFont(sfBuf);
s.setGain(this.midiGain * 0.5);
const node = s.createAudioNode(ctx, 4096);
node.connect(ctx.destination);
this.synth = s;
this.synthNode = node;
this.synthReady = true;
if (this.pendingMidi && this.ctx && this.ctx.state === 'running') {
const pending = this.pendingMidi;
this.pendingMidi = null;
this.playMidi(pending, this.midiGain, this.midiLoop);
}
return s;
} catch (e) {
console.warn('FluidSynth init error:', e);
this.synthLoading = null;
return null;
}
})();
return this.synthLoading;
},
decodeWav8MonoSync(ctx, bytes) {
if (!bytes || bytes.length < 44) return null;
if (bytes[0] !== 0x52 || bytes[1] !== 0x49 || bytes[2] !== 0x46 || bytes[3] !== 0x46) return null; // RIFF
if (bytes[8] !== 0x57 || bytes[9] !== 0x41 || bytes[10] !== 0x56 || bytes[11] !== 0x45) return null; // WAVE
const audioFmt = bytes[20] | (bytes[21] << 8);
const channels = bytes[22] | (bytes[23] << 8);
const bitsPerSample = bytes[34] | (bytes[35] << 8);
if (audioFmt !== 1 || channels !== 1 || bitsPerSample !== 8) return null;
if (bytes[36] !== 0x64 || bytes[37] !== 0x61 || bytes[38] !== 0x74 || bytes[39] !== 0x61) return null; // data
const sampleRate = (bytes[24] | (bytes[25] << 8) | (bytes[26] << 16) | (bytes[27] << 24)) >>> 0;
const dataSize = Math.min(
(bytes[40] | (bytes[41] << 8) | (bytes[42] << 16) | (bytes[43] << 24)) >>> 0,
bytes.length - 44
);
if (sampleRate < 4000 || dataSize <= 0) return null;
const buf = ctx.createBuffer(1, dataSize, sampleRate);
const out = buf.getChannelData(0);
for (let i = 0; i < dataSize; i++) {
out[i] = (bytes[44 + i] - 128) / 128.0;
}
return buf;
},
playBuffer(ctx, buf, volume, delayMs) {
const src = ctx.createBufferSource();
const gain = ctx.createGain();
gain.gain.value = Math.max(0, Math.min(1, volume));
src.buffer = buf;
src.connect(gain);
gain.connect(ctx.destination);
const startAt = (delayMs && delayMs > 0) ? (ctx.currentTime + delayMs / 1000.0) : 0;
src.start(startAt);
},
playPcm(bytes, volume, delayMs) {
const ctx = this.ensureCtx();
if (!ctx || ctx.state === 'suspended' || !bytes || bytes.length === 0) return;
const syncBuf = this.decodeWav8MonoSync(ctx, bytes);
if (syncBuf) {
this.playBuffer(ctx, syncBuf, volume, delayMs);
return;
}
const copy = new Uint8Array(bytes).buffer;
ctx.decodeAudioData(copy).then(buf => {
this.playBuffer(ctx, buf, volume, delayMs);
}).catch(() => {});
},
async playMidi(bytes, volume, loop) {
this.midiGain = Math.max(0, Math.min(1, volume));
if (typeof loop === 'boolean') this.midiLoop = loop;
if (!bytes || bytes.length === 0) return;
this.lastMidiBytes = new Uint8Array(bytes);
const seq = ++this.midiPlaySeq;
this.ensureCtx();
if (!this.synthReady) {
this.pendingMidi = new Uint8Array(bytes);
this.ensureFluidSynth();
return;
}
if (this.ctx && this.ctx.state === 'suspended') {
this.pendingMidi = new Uint8Array(bytes);
return;
}
this.pendingMidi = null;
try {
const copy = new Uint8Array(bytes).buffer;
this.synth.setGain(this.midiGain * 0.5);
await this.synth.stopPlayer();
if (seq !== this.midiPlaySeq) return;
await this.synth.resetPlayer();
if (seq !== this.midiPlaySeq) return;
await this.synth.addSMFDataToPlayer(copy);
if (seq !== this.midiPlaySeq) return;
if (this.synth.setPlayerLoop) {
this.synth.setPlayerLoop(this.midiLoop === false ? 0 : -1);
}
await this.synth.playPlayer();
} catch (e) {
console.warn('FluidSynth MIDI playback error:', e);
}
},
setMidiLoop(loop, restartIfStopped) {
this.midiLoop = !!loop;
if (this.synthReady && this.synth && this.synth.setPlayerLoop) {
try { this.synth.setPlayerLoop(this.midiLoop ? -1 : 0); } catch (_) {}
}
if (restartIfStopped && this.lastMidiBytes && this.synthReady && this.synth) {
try {
if (this.synth.isPlaying && !this.synth.isPlaying()) {
this.playMidi(this.lastMidiBytes, this.midiGain, this.midiLoop);
}
} catch (_) {}
}
},
setMidiVolume(volume) {
this.midiGain = Math.max(0, Math.min(1, volume));
if (this.synthReady && this.synth) {
this.synth.setGain(this.midiGain * 0.5);
}
},
stopMidi() {
this.midiPlaySeq++;
this.pendingMidi = null;
if (this.synthReady && this.synth) {
try { this.synth.stopPlayer(); } catch (_) {}
}
}
};
window.scapeClipboardText = '';
window.addEventListener('paste', (e) => {
try {
const txt = e.clipboardData ? e.clipboardData.getData('text') : '';
if (txt) window.scapeClipboardText = txt;
} catch (_) {}
});
window.addEventListener('focus', () => {
if (navigator.clipboard && navigator.clipboard.readText) {
navigator.clipboard.readText().then(t => { if (typeof t === 'string') window.scapeClipboardText = t; }).catch(() => {});
}
}, { passive: true });
window.scapeWebAudio.preloadFluidSynthAssets();
['pointerdown', 'keydown', 'touchstart'].forEach(evt => {
window.addEventListener(evt, () => {
window.scapeWebAudio.ensureCtx();
window.scapeWebAudio.ensureFluidSynth();
}, { passive: true });
});
// Cache preloader (IndexedDB + HTTP fetch)
window.scapePreloadCache = async function(cb) {
const files = ['main_file_cache.dat', 'main_file_cache.idx0', 'main_file_cache.idx1', 'main_file_cache.idx2', 'main_file_cache.idx3', 'main_file_cache.idx4'];
const openDb = () => new Promise((resolve) => {
if (!window.indexedDB) { resolve(null); return; }
const req = indexedDB.open('2006scape_cache_v1', 1);
req.onupgradeneeded = () => req.result.createObjectStore('files');
req.onsuccess = () => resolve(req.result);
req.onerror = () => resolve(null);
});
const dbGet = (db, key) => new Promise((resolve) => {
if (!db) { resolve(null); return; }
const tx = db.transaction('files', 'readonly');
const req = tx.objectStore('files').get(key);
req.onsuccess = () => resolve(req.result || null);
req.onerror = () => resolve(null);
});
const dbPut = (db, key, val) => new Promise((resolve) => {
if (!db) { resolve(); return; }
const tx = db.transaction('files', 'readwrite');
tx.objectStore('files').put(val, key);
tx.oncomplete = () => resolve();
tx.onerror = () => resolve();
});
const db = await openDb();
const results = [];
const fillEl = document.getElementById('progress-fill');
const lblEl = document.getElementById('loading-text');
for (let i = 0; i < files.length; i++) {
const name = files[i];
const pct = 15 + Math.floor((i / files.length) * 80);
if (fillEl) fillEl.style.width = pct + '%';
if (lblEl) lblEl.textContent = 'Loading ' + name + '...';
let buf = await dbGet(db, name);
if (!buf) {
try {
const resp = await fetch('cache/' + name);
if (resp.ok) {
buf = new Uint8Array(await resp.arrayBuffer());
await dbPut(db, name, buf);
}
} catch (_) {}
}
results.push(buf || new Uint8Array(0));
}
if (fillEl) fillEl.style.width = '95%';
if (lblEl) lblEl.textContent = 'Booting game engine...';
cb(results[0], results[1], results[2], results[3], results[4], results[5]);
};
// Script import handler into localStorage virtual FS
document.getElementById('script-upload').addEventListener('change', async (ev) => {
for (const file of ev.target.files) {
const text = await file.text();
localStorage.setItem('2006scape_script_' + file.name, text);
console.log('[2006Scape-Web] Imported script:', file.name);
}
ev.target.value = '';
});
window.scapeInitNavbar = function(visible, mainMenuUrl, worldMapUrl, manualUrl, rulesUrl) {
const nav = document.getElementById('rs-navbar');
if (!nav) return;
nav.classList.toggle('visible', !!visible);
const setHref = (id, url) => {
const el = document.getElementById(id);
if (el && url) el.href = url;
};
setHref('nav-mainmenu', mainMenuUrl);
setHref('nav-worldmap', worldMapUrl);
setHref('nav-manual', manualUrl);
setHref('nav-rules', rulesUrl);
};
(function() {
const OPT_KEY = '2006scape_web_options';
const modal = document.getElementById('options-modal');
const btnOpen = document.getElementById('btn-options');
const btnClose = document.getElementById('opt-close');
const btnCancel = document.getElementById('opt-cancel');
const btnSave = document.getElementById('opt-save');
const btnSaveReload = document.getElementById('opt-save-reload');
function loadOpts() {
try {
return JSON.parse(localStorage.getItem(OPT_KEY) || '{}') || {};
} catch (_) { return {}; }
}
function populateModal() {
const o = loadOpts();
const params = new URLSearchParams(window.location.search);
document.getElementById('opt-autologin').checked = !!o.autoLogin;
document.getElementById('opt-username').value = o.username || '';
document.getElementById('opt-password').value = o.password || '';
document.getElementById('opt-server').value = o.server || params.get('server') || '192.168.1.88';
document.getElementById('opt-world').value = o.world || params.get('world') || '1';
document.getElementById('opt-hd').checked = (o.hd !== undefined) ? !!o.hd : (params.get('hd') === 'true' || params.get('hd') === '1');
document.getElementById('opt-mode').value = String(window.scapeDisplayMode !== undefined ? window.scapeDisplayMode : (o.displayMode || 0));
const nav = document.getElementById('rs-navbar');
document.getElementById('opt-navbar').checked = (o.navbar !== undefined) ? !!o.navbar : (nav ? nav.classList.contains('visible') : true);
document.getElementById('opt-pause-bg').checked = !!o.pauseInBackground;
}
function saveOpts(applyLive) {
const o = {
autoLogin: document.getElementById('opt-autologin').checked,
username: document.getElementById('opt-username').value.trim(),
password: document.getElementById('opt-password').value,
server: document.getElementById('opt-server').value.trim() || '192.168.1.88',
world: parseInt(document.getElementById('opt-world').value, 10) || 1,
hd: document.getElementById('opt-hd').checked,
displayMode: parseInt(document.getElementById('opt-mode').value, 10) || 0,
navbar: document.getElementById('opt-navbar').checked,
pauseInBackground: document.getElementById('opt-pause-bg').checked
};
try {
localStorage.setItem(OPT_KEY, JSON.stringify(o));
const props = localStorage.getItem('2006scape_plugin_settings') || '';
const lines = props ? props.split(/\r?\n/) : [];
let found = false;
for (let i = 0; i < lines.length; i++) {
if (lines[i].startsWith('plugin.317_HD.enabled=')) {
lines[i] = 'plugin.317_HD.enabled=' + o.hd;
found = true;
}
}
if (!found) lines.push('plugin.317_HD.enabled=' + o.hd);
localStorage.setItem('2006scape_plugin_settings', lines.filter(Boolean).join('\n') + '\n');
} catch (_) {}
if (applyLive) {
window.scapePauseInBackground = !!o.pauseInBackground;
if (typeof window.scapeSetHd317 === 'function') {
window.scapeSetHd317(o.hd);
}
const nav = document.getElementById('rs-navbar');
if (nav) nav.classList.toggle('visible', o.navbar);
if (typeof window.scapeDisplayMode === 'number' && window.scapeDisplayMode !== o.displayMode) {
window.scapeDisplayMode = o.displayMode;
const reqFs = document.documentElement.requestFullscreen || document.documentElement.webkitRequestFullscreen;
if (o.displayMode === 2 && !document.fullscreenElement && reqFs) {
Promise.resolve(reqFs.call(document.documentElement)).catch(() => {
window.scapeDisplayMode = 1;
});
} else if (o.displayMode !== 2 && document.fullscreenElement && document.exitFullscreen) {
document.exitFullscreen().catch(() => {});
}
}
fitFixedCanvasToViewport();
}
}
if (btnOpen) btnOpen.addEventListener('click', () => { populateModal(); modal.classList.add('open'); });
if (btnClose) btnClose.addEventListener('click', () => modal.classList.remove('open'));
if (btnCancel) btnCancel.addEventListener('click', () => modal.classList.remove('open'));
if (modal) modal.addEventListener('click', (e) => { if (e.target === modal) modal.classList.remove('open'); });
if (btnSave) btnSave.addEventListener('click', () => { saveOpts(true); modal.classList.remove('open'); });
if (btnSaveReload) btnSaveReload.addEventListener('click', () => { saveOpts(false); window.location.reload(); });
window.scapePauseInBackground = !!loadOpts().pauseInBackground;
document.addEventListener('visibilitychange', () => {
if (!window.scapePauseInBackground) return;
const audio = window.scapeWebAudio;
if (!audio || !audio.ctx) return;
if (document.hidden) {
if (audio.ctx.state === 'running') {
window.scapePausedAudio = true;
audio.ctx.suspend().catch(() => {});
}
} else if (window.scapePausedAudio) {
window.scapePausedAudio = false;
audio.ctx.resume().catch(() => {});
}
});
})();
function updateCachedStageSize() {
const s = document.getElementById('stage');
const nav = document.getElementById('rs-navbar');
let w = s ? s.clientWidth : window.innerWidth;
let h = s ? s.clientHeight : window.innerHeight;
if (window.visualViewport) {
w = Math.min(w, Math.floor(window.visualViewport.width));
h = Math.min(h, Math.floor(window.visualViewport.height));
}
if (nav && nav.offsetHeight > 0) h -= 25;
window.scapeStageW = Math.max(1, w);
window.scapeStageH = Math.max(1, h);
}
function fitFixedCanvasToViewport() {
const footer = document.getElementById('rs-footer');
const frame = document.getElementById('rs-frame');
const navInner = document.getElementById('rs-navbar-inner');
if (footer) footer.classList.toggle('floating', window.scapeDisplayMode !== 0);
if (window.scapeDisplayMode !== 0) {
if (frame) {
frame.style.width = '100%';
frame.style.height = '100%';
}
if (navInner) navInner.style.transform = '';
updateCachedStageSize();
return;
}
if (frame) frame.style.height = '';
const stage = document.getElementById('stage');
const gc = document.getElementById('game-canvas');
const nav = document.getElementById('rs-navbar');
if (!stage || !gc) return;
const vw = Math.min(document.documentElement.clientWidth || window.innerWidth, window.visualViewport ? window.visualViewport.width : window.innerWidth);
const vh = window.visualViewport ? window.visualViewport.height : window.innerHeight;
const footerH = footer ? (footer.offsetHeight + 8) : 24;
const navVisible = nav && nav.offsetHeight > 0;
const navH = navVisible ? 25 : 0;
const sw = vw;
const sh = Math.max(120, vh - footerH - navH - 8);
if (sw > 0 && sh > 0 && (sw < 765 || sh < 503)) {
const scale = Math.min(sw / 765, sh / 503);
const fw = Math.floor(765 * scale);
const fh = Math.floor(503 * scale);
gc.style.width = fw + 'px';
gc.style.height = fh + 'px';
if (frame) frame.style.width = fw + 'px';
if (nav) nav.style.width = fw + 'px';
if (navInner) {
navInner.style.transformOrigin = 'center center';
navInner.style.transform = 'scale(' + Math.min(1, fw / 765) + ')';
}
} else {
gc.style.width = '765px';
gc.style.height = '503px';
if (frame) frame.style.width = '';
if (nav) nav.style.width = '765px';
if (navInner) navInner.style.transform = '';
}
updateCachedStageSize();
}
window.addEventListener('resize', fitFixedCanvasToViewport);
if (window.visualViewport) window.visualViewport.addEventListener('resize', fitFixedCanvasToViewport);
setTimeout(fitFixedCanvasToViewport, 100);
(function() {
const params = new URLSearchParams(window.location.search);
const hasResize = params.has('resize');
const isResize = params.get('resize') === 'true' || params.get('resize') === '1';
let savedMode = 0;
try {
const o = JSON.parse(localStorage.getItem('2006scape_web_options') || '{}');
if (o && typeof o.displayMode === 'number') savedMode = o.displayMode;
} catch (_) {}
window.scapeDisplayMode = hasResize ? (isResize ? 1 : 0) : (savedMode === 2 ? 1 : savedMode); // 0=Fixed, 1=Resizable, 2=Fullscreen
document.addEventListener('fullscreenchange', () => {
if (!document.fullscreenElement) {
if (window.scapeDisplayMode === 2) {
window.scapeDisplayMode = 1;
} else if (window.scapeDisplayMode === 0) {
const glc = document.getElementById('gl-canvas');
if (glc) {
glc.width = 765;
glc.height = 503;
}
}
}
});
})();
</script>
<script type="text/javascript" charset="utf-8" src="js/client.js" onload="main()"></script>
<script>
if ('serviceWorker' in navigator) {
window.addEventListener('load', () => {
navigator.serviceWorker.register('sw.js').catch(() => {});
});
}
</script>
</body>
</html>