diff --git a/src/main/java/org/scape2006/web/Class56_Sub1_Sub1.java b/src/main/java/org/scape2006/web/Class56_Sub1_Sub1.java index 6d04109..1604902 100644 --- a/src/main/java/org/scape2006/web/Class56_Sub1_Sub1.java +++ b/src/main/java/org/scape2006/web/Class56_Sub1_Sub1.java @@ -9,12 +9,17 @@ public final class Class56_Sub1_Sub1 extends Class56 { @Override void method827(int volume, byte[] midiBytes, int unused, boolean loop) { if (midiBytes != null && midiBytes.length > 0) { - DesktopHooks.playMidiBytes(midiBytes, volume); + DesktopHooks.playMidiBytes(midiBytes, volume, loop); } else { DesktopHooks.stopSignlinkMidi(); } } + @Override + void setLoop(boolean loop, boolean restartIfStopped) { + DesktopHooks.setMidiLoop(loop, restartIfStopped); + } + @Override void method828() { DesktopHooks.stopSignlinkMidi(); diff --git a/src/main/java/org/scape2006/web/DesktopHooks.java b/src/main/java/org/scape2006/web/DesktopHooks.java index 74703cb..f5760d9 100644 --- a/src/main/java/org/scape2006/web/DesktopHooks.java +++ b/src/main/java/org/scape2006/web/DesktopHooks.java @@ -88,14 +88,28 @@ public final class DesktopHooks { private static native void jsDecodeImage(Uint8Array bytes, ImageDecodeCallback cb); public static String getClipBoard() { - return ""; + String raw = jsGetClipboardText(); + if (raw == null || raw.isEmpty()) return ""; + StringBuilder out = new StringBuilder(raw.length()); + for (int i = 0; i < raw.length(); i++) { + char c = raw.charAt(i); + if (c >= 32 && c <= 122) { + out.append(c); + } + } + return out.toString(); } public static void takeScreenshot(Game game, boolean sendMessage, String... subfolders) { ensureHudAssets(); HTMLCanvasElement canvas = RSImageProducer.getCanvas(); if (canvas != null) { - downloadCanvasPng(canvas, "2006scape_" + System.currentTimeMillis() + ".png"); + String prefix = (game != null && game.myUsername != null && !game.myUsername.isEmpty()) + ? game.myUsername : ClientSettings.SERVER_NAME; + downloadCanvasPng(canvas, prefix + "_" + System.currentTimeMillis() + ".png"); + if (sendMessage && game != null) { + game.pushMessage("A picture has been downloaded.", 0, ""); + } } } @@ -137,11 +151,19 @@ public final class DesktopHooks { } public static void playMidiBytes(byte[] midiBytes, int vol) { + playMidiBytes(midiBytes, vol, true); + } + + public static void playMidiBytes(byte[] midiBytes, int vol, boolean loop) { if (midiBytes == null || midiBytes.length == 0) return; midiVolume = Math.max(0.0f, Math.min(1.0f, vol / 255.0f)); Uint8Array arr = Uint8Array.create(midiBytes.length); arr.set(midiBytes, 0); - jsPlayMidi(arr, midiVolume); + jsPlayMidi(arr, midiVolume, loop); + } + + public static void setMidiLoop(boolean loop, boolean restartIfStopped) { + jsSetMidiLoop(loop, restartIfStopped); } public static boolean setSignlinkVolume(int vol) { @@ -161,7 +183,6 @@ public final class DesktopHooks { public static void drawModernMinimap(Object graphics, int[] minimapPixels, int windowWidth) { if (minimapPixels == null || minimapPixels.length < 172 * 156) return; ensureHudAssets(); - ensureHudAssets(); HTMLCanvasElement canvas = RSImageProducer.getCanvas(); if (canvas == null) return; Uint8ClampedArray rgba = toRgbaOpaque(minimapPixels, 172 * 156); @@ -489,9 +510,16 @@ public final class DesktopHooks { "if (window.scapeWebAudio && window.scapeWebAudio.playPcm) window.scapeWebAudio.playPcm(arr, vol, delayMs);") private static native void jsPlayPcm(Uint8Array arr, float vol, int delayMs); - @JSBody(params = {"arr", "vol"}, script = - "if (window.scapeWebAudio && window.scapeWebAudio.playMidi) window.scapeWebAudio.playMidi(arr, vol);") - private static native void jsPlayMidi(Uint8Array arr, float vol); + @JSBody(params = {"arr", "vol", "loop"}, script = + "if (window.scapeWebAudio && window.scapeWebAudio.playMidi) window.scapeWebAudio.playMidi(arr, vol, loop);") + private static native void jsPlayMidi(Uint8Array arr, float vol, boolean loop); + + @JSBody(params = {"loop", "restartIfStopped"}, script = + "if (window.scapeWebAudio && window.scapeWebAudio.setMidiLoop) window.scapeWebAudio.setMidiLoop(loop, restartIfStopped);") + private static native void jsSetMidiLoop(boolean loop, boolean restartIfStopped); + + @JSBody(script = "return window.scapeClipboardText || '';") + private static native String jsGetClipboardText(); @JSBody(params = {"vol"}, script = "if (window.scapeWebAudio && window.scapeWebAudio.setMidiVolume) window.scapeWebAudio.setMidiVolume(vol);") diff --git a/src/main/java/org/scape2006/web/WebReflectionSupplier.java b/src/main/java/org/scape2006/web/WebReflectionSupplier.java index 41e56f3..c6436de 100644 --- a/src/main/java/org/scape2006/web/WebReflectionSupplier.java +++ b/src/main/java/org/scape2006/web/WebReflectionSupplier.java @@ -41,10 +41,12 @@ public final class WebReflectionSupplier implements ReflectionSupplier { SCRIPTABLE_CLASSES.add(p + "PluginContext$PlayerQuery"); SCRIPTABLE_CLASSES.add(p + "PluginGraphics"); SCRIPTABLE_CLASSES.add(p + "PluginConfigItem"); + SCRIPTABLE_CLASSES.add(p + "MenuEntry"); SCRIPTABLE_CLASSES.add(p + "ClientScript"); SCRIPTABLE_CLASSES.add(p + "ClientPlugin"); SCRIPTABLE_CLASSES.add(p + "ClientSettings"); SCRIPTABLE_CLASSES.add(p + "ScriptLogger"); + SCRIPTABLE_CLASSES.add(p + "WorldWebWalker"); SCRIPTABLE_CLASSES.add(p + "Game"); SCRIPTABLE_CLASSES.add(p + "Player"); SCRIPTABLE_CLASSES.add(p + "NPC"); @@ -116,12 +118,15 @@ public final class WebReflectionSupplier implements ReflectionSupplier { if (!"length".equals(name) && !"equals".equals(name) && !"equalsIgnoreCase".equals(name) && !"contains".equals(name) && !"startsWith".equals(name) && !"endsWith".equals(name) && !"toLowerCase".equals(name) && !"toUpperCase".equals(name) && !"trim".equals(name) - && !"substring".equals(name) && !"indexOf".equals(name) && !"replace".equals(name) + && !"substring".equals(name) && !"indexOf".equals(name) && !"lastIndexOf".equals(name) + && !"replace".equals(name) && !"charAt".equals(name) && !"split".equals(name) && !"isEmpty".equals(name) && !"valueOf".equals(name)) continue; } else if (isUtilColl) { if (!"size".equals(name) && !"isEmpty".equals(name) && !"get".equals(name) - && !"add".equals(name) && !"remove".equals(name) && !"clear".equals(name) - && !"contains".equals(name) && !"containsKey".equals(name) && !"put".equals(name)) continue; + && !"set".equals(name) && !"add".equals(name) && !"remove".equals(name) + && !"clear".equals(name) && !"contains".equals(name) && !"indexOf".equals(name) + && !"containsKey".equals(name) && !"containsValue".equals(name) + && !"put".equals(name) && !"keySet".equals(name) && !"values".equals(name)) continue; } methods.add(m.getDescriptor()); } diff --git a/src/main/webapp/index.html b/src/main/webapp/index.html index fe5f35e..1fc29e5 100644 --- a/src/main/webapp/index.html +++ b/src/main/webapp/index.html @@ -448,7 +448,7 @@ if (this.pendingMidi && this.synthReady && this.ctx && this.ctx.state === 'running') { const pending = this.pendingMidi; this.pendingMidi = null; - this.playMidi(pending, this.midiGain); + this.playMidi(pending, this.midiGain, this.midiLoop); } }).catch(() => {}); } @@ -494,7 +494,7 @@ if (this.pendingMidi && this.ctx && this.ctx.state === 'running') { const pending = this.pendingMidi; this.pendingMidi = null; - this.playMidi(pending, this.midiGain); + this.playMidi(pending, this.midiGain, this.midiLoop); } return s; } catch (e) { @@ -550,9 +550,11 @@ this.playBuffer(ctx, buf, volume, delayMs); }).catch(() => {}); }, - async playMidi(bytes, volume) { + 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) { @@ -575,13 +577,26 @@ await this.synth.addSMFDataToPlayer(copy); if (seq !== this.midiPlaySeq) return; if (this.synth.setPlayerLoop) { - this.synth.setPlayerLoop(-1); + 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) { @@ -596,6 +611,18 @@ } } }; + 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, () => {