使用 HTML 运行《半条命》(以及《反恐精英 1.6》)

1作者: yohimik5 个月前
没有标题党,只有纯 HTML、CSS、JavaScript 和 WASM<p>只需复制并粘贴此 HTML 代码即可运行《半条命》<p>https://www.npmjs.com/package/xash3d-fwgs<p>https://www.npmjs.com/package/cs16-client<p>https://www.npmjs.com/package/hlsdk-portable<p>https://github.com/yohimik/webxash3d-fwgs<p>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;加载中&lt;&#x2F;title&gt; &lt;style&gt; canvas { width: 100vw; height: 100vh; top: 0; left: 0; position: fixed; }<p><pre><code> body { margin: 0; } &lt;&#x2F;style&gt; &lt;script src=&quot;https:&#x2F;&#x2F;cdn.jsdelivr.net&#x2F;npm&#x2F;xash3d-fwgs@latest&#x2F;dist&#x2F;raw.js&quot;&gt;&lt;&#x2F;script&gt;</code></pre> &lt;&#x2F;head&gt; &lt;body&gt; &lt;canvas id=&quot;canvas&quot;&gt;&lt;&#x2F;canvas&gt; &lt;script type=&quot;module&quot;&gt; import JSZip from &#x27;https:&#x2F;&#x2F;cdn.skypack.dev&#x2F;jszip@3.10.1&#x27;;<p><pre><code> async function main() { const files = {} const res = await fetch(&#x27;https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;x8BitRain&#x2F;webXash&#x2F;main&#x2F;public&#x2F;hl&#x2F;hldm.zip&#x27;) const zip = await JSZip.loadAsync(await res.arrayBuffer()); await Promise.all(Object.keys(zip.files).map(async p =&gt; { const file = zip.files[p] if (file.dir) return; const path = `&#x2F;rodir&#x2F;${p}`; files[path] = await file.async(&quot;uint8array&quot;) })) Xash3D({ arguments: [&#x27;-windowed&#x27;], canvas: document.getElementById(&#x27;canvas&#x27;), ctx: document.getElementById(&#x27;canvas&#x27;) .getContext(&#x27;webgl2&#x27;, { alpha: false, depth: true, stencil: true, antialias: true }), dynamicLibraries: [ &quot;filesystem_stdio.wasm&quot;, &quot;libref_gles3compat.wasm&quot;, &quot;cl_dlls&#x2F;menu_emscripten_wasm32.wasm&quot;, &quot;dlls&#x2F;hl_emscripten_wasm32.so&quot;, &quot;cl_dlls&#x2F;client_emscripten_wasm32.wasm&quot;, ], onRuntimeInitialized: function () { Object.keys(files) .forEach(k =&gt; { const dir = k.split(&#x27;&#x2F;&#x27;) .slice(0, -1) .join(&#x27;&#x2F;&#x27;); this.FS.mkdirTree(dir); this.FS.writeFile(k, files[k]); }) this.FS.chdir(&#x27;&#x2F;rodir&#x27;) }, locateFile: (p) =&gt; { switch (p) { case &#x27;xash.wasm&#x27;: return &#x27;https:&#x2F;&#x2F;cdn.jsdelivr.net&#x2F;npm&#x2F;xash3d-fwgs@latest&#x2F;dist&#x2F;xash.wasm&#x27; case &#x27;filesystem_stdio.wasm&#x27;: return &#x27;https:&#x2F;&#x2F;cdn.jsdelivr.net&#x2F;npm&#x2F;xash3d-fwgs@latest&#x2F;dist&#x2F;filesystem_stdio.wasm&#x27; case &#x27;libref_gles3compat.wasm&#x27;: return &#x27;https:&#x2F;&#x2F;cdn.jsdelivr.net&#x2F;npm&#x2F;xash3d-fwgs@latest&#x2F;dist&#x2F;libref_gles3compat.wasm&#x27; case &#x27;cl_dlls&#x2F;menu_emscripten_wasm32.wasm&#x27;: return &#x27;https:&#x2F;&#x2F;cdn.jsdelivr.net&#x2F;npm&#x2F;xash3d-fwgs@latest&#x2F;dist&#x2F;cl_dll&#x2F;menu_emscripten_wasm32.wasm&#x27; case &#x27;dlls&#x2F;hl_emscripten_wasm32.so&#x27;: return &#x27;https:&#x2F;&#x2F;cdn.jsdelivr.net&#x2F;npm&#x2F;hlsdk-portable@latest&#x2F;dist&#x2F;dlls&#x2F;hl_emscripten_wasm32.so&#x27; case &#x27;cl_dlls&#x2F;client_emscripten_wasm32.wasm&#x27;: return &#x27;https:&#x2F;&#x2F;cdn.jsdelivr.net&#x2F;npm&#x2F;hlsdk-portable@latest&#x2F;dist&#x2F;cl_dll&#x2F;client_emscripten_wasm32.wasm&#x27; default: return p } }, }) } main()</code></pre> &lt;&#x2F;script&gt; &lt;&#x2F;body&gt; &lt;&#x2F;html&gt;
查看原文
No clickbait, just pure HTML, CSS, JavaScript, and WASM<p>Simply copy and paste this HTML code and run Half-Life<p>https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;xash3d-fwgs<p>https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;cs16-client<p>https:&#x2F;&#x2F;www.npmjs.com&#x2F;package&#x2F;hlsdk-portable<p>https:&#x2F;&#x2F;github.com&#x2F;yohimik&#x2F;webxash3d-fwgs<p>&lt;!DOCTYPE html&gt; &lt;html&gt; &lt;head&gt; &lt;title&gt;Loading&lt;&#x2F;title&gt; &lt;style&gt; canvas { width: 100vw; height: 100vh; top: 0; left: 0; position: fixed; }<p><pre><code> body { margin: 0; } &lt;&#x2F;style&gt; &lt;script src=&quot;https:&#x2F;&#x2F;cdn.jsdelivr.net&#x2F;npm&#x2F;xash3d-fwgs@latest&#x2F;dist&#x2F;raw.js&quot;&gt;&lt;&#x2F;script&gt;</code></pre> &lt;&#x2F;head&gt; &lt;body&gt; &lt;canvas id=&quot;canvas&quot;&gt;&lt;&#x2F;canvas&gt; &lt;script type=&quot;module&quot;&gt; import JSZip from &#x27;https:&#x2F;&#x2F;cdn.skypack.dev&#x2F;jszip@3.10.1&#x27;;<p><pre><code> async function main() { const files = {} const res = await fetch(&#x27;https:&#x2F;&#x2F;raw.githubusercontent.com&#x2F;x8BitRain&#x2F;webXash&#x2F;main&#x2F;public&#x2F;hl&#x2F;hldm.zip&#x27;) const zip = await JSZip.loadAsync(await res.arrayBuffer()); await Promise.all(Object.keys(zip.files).map(async p =&gt; { const file = zip.files[p] if (file.dir) return; const path = `&#x2F;rodir&#x2F;${p}`; files[path] = await file.async(&quot;uint8array&quot;) })) Xash3D({ arguments: [&#x27;-windowed&#x27;], canvas: document.getElementById(&#x27;canvas&#x27;), ctx: document.getElementById(&#x27;canvas&#x27;) .getContext(&#x27;webgl2&#x27;, { alpha: false, depth: true, stencil: true, antialias: true }), dynamicLibraries: [ &quot;filesystem_stdio.wasm&quot;, &quot;libref_gles3compat.wasm&quot;, &quot;cl_dlls&#x2F;menu_emscripten_wasm32.wasm&quot;, &quot;dlls&#x2F;hl_emscripten_wasm32.so&quot;, &quot;cl_dlls&#x2F;client_emscripten_wasm32.wasm&quot;, ], onRuntimeInitialized: function () { Object.keys(files) .forEach(k =&gt; { const dir = k.split(&#x27;&#x2F;&#x27;) .slice(0, -1) .join(&#x27;&#x2F;&#x27;); this.FS.mkdirTree(dir); this.FS.writeFile(k, files[k]); }) this.FS.chdir(&#x27;&#x2F;rodir&#x27;) }, locateFile: (p) =&gt; { switch (p) { case &#x27;xash.wasm&#x27;: return &#x27;https:&#x2F;&#x2F;cdn.jsdelivr.net&#x2F;npm&#x2F;xash3d-fwgs@latest&#x2F;dist&#x2F;xash.wasm&#x27; case &#x27;filesystem_stdio.wasm&#x27;: return &#x27;https:&#x2F;&#x2F;cdn.jsdelivr.net&#x2F;npm&#x2F;xash3d-fwgs@latest&#x2F;dist&#x2F;filesystem_stdio.wasm&#x27; case &#x27;libref_gles3compat.wasm&#x27;: return &#x27;https:&#x2F;&#x2F;cdn.jsdelivr.net&#x2F;npm&#x2F;xash3d-fwgs@latest&#x2F;dist&#x2F;libref_gles3compat.wasm&#x27; case &#x27;cl_dlls&#x2F;menu_emscripten_wasm32.wasm&#x27;: return &#x27;https:&#x2F;&#x2F;cdn.jsdelivr.net&#x2F;npm&#x2F;xash3d-fwgs@latest&#x2F;dist&#x2F;cl_dll&#x2F;menu_emscripten_wasm32.wasm&#x27; case &#x27;dlls&#x2F;hl_emscripten_wasm32.so&#x27;: return &#x27;https:&#x2F;&#x2F;cdn.jsdelivr.net&#x2F;npm&#x2F;hlsdk-portable@latest&#x2F;dist&#x2F;dlls&#x2F;hl_emscripten_wasm32.so&#x27; case &#x27;cl_dlls&#x2F;client_emscripten_wasm32.wasm&#x27;: return &#x27;https:&#x2F;&#x2F;cdn.jsdelivr.net&#x2F;npm&#x2F;hlsdk-portable@latest&#x2F;dist&#x2F;cl_dll&#x2F;client_emscripten_wasm32.wasm&#x27; default: return p } }, }) } main()</code></pre> &lt;&#x2F;script&gt; &lt;&#x2F;body&gt; &lt;&#x2F;html&gt;