eaglercraft-1.8-workspace/wasm_gc_teavm/javascript/loader.js
eaglercraft c67fe4733e u44
2024-12-04 00:39:49 -08:00

2 lines
18 KiB
JavaScript
Executable File

var Module=typeof Module!="undefined"?Module:{};var ENVIRONMENT_IS_WEB=typeof window=="object";var ENVIRONMENT_IS_WORKER=typeof WorkerGlobalScope!="undefined";var ENVIRONMENT_IS_NODE=typeof process=="object"&&typeof process.versions=="object"&&typeof process.versions.node=="string"&&process.type!="renderer";if(ENVIRONMENT_IS_NODE){}Module["locateFile"]=function(path){if(path==="loader.wasm"){return window.__eaglercraftXLoaderContextPre.loaderWASMURL}else{return path}};const rootElement=window.__eaglercraftXLoaderContextPre.rootElement;const optsObj=window.__eaglercraftXLoaderContextPre.eaglercraftXOpts;const epwFile=window.__eaglercraftXLoaderContextPre.theEPWFileBuffer;const splashURL=window.__eaglercraftXLoaderContextPre.splashURL;const results=[null];function createCrashParentElement(){var oldSplash=null;var node;while(node=rootElement.lastChild){if(!oldSplash){oldSplash=node}rootElement.removeChild(node)}const parentElement=document.createElement("div");parentElement.classList.add("_eaglercraftX_wrapper_element");parentElement.setAttribute("style","position:relative;width:100%;height:100%;overflow:hidden;");if(oldSplash){oldSplash.classList.add("_eaglercraftX_early_splash_element");oldSplash.style.position="absolute";oldSplash.style.top="0px";oldSplash.style.left="0px";oldSplash.style.right="0px";oldSplash.style.bottom="0px";oldSplash.style.zIndex="2";parentElement.appendChild(oldSplash)}rootElement.appendChild(parentElement);return parentElement}var moduleOverrides=Object.assign({},Module);var arguments_=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_NODE){var fs=require("fs");var nodePath=require("path");scriptDirectory=__dirname+"/";readBinary=filename=>{filename=isFileURI(filename)?new URL(filename):nodePath.normalize(filename);var ret=fs.readFileSync(filename);return ret};readAsync=(filename,binary=true)=>{filename=isFileURI(filename)?new URL(filename):nodePath.normalize(filename);return new Promise((resolve,reject)=>{fs.readFile(filename,binary?undefined:"utf8",(err,data)=>{if(err)reject(err);else resolve(binary?data.buffer:data)})})};if(!Module["thisProgram"]&&process.argv.length>1){thisProgram=process.argv[1].replace(/\\/g,"/")}arguments_=process.argv.slice(2);if(typeof module!="undefined"){module["exports"]=Module}quit_=(status,toThrow)=>{process.exitCode=status;throw toThrow}}else if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){if(ENVIRONMENT_IS_WORKER){scriptDirectory=self.location.href}else if(typeof document!="undefined"&&document.currentScript){scriptDirectory=document.currentScript.src}if(scriptDirectory.startsWith("blob:")){scriptDirectory=""}else{scriptDirectory=scriptDirectory.substr(0,scriptDirectory.replace(/[?#].*/,"").lastIndexOf("/")+1)}{if(ENVIRONMENT_IS_WORKER){readBinary=url=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,false);xhr.responseType="arraybuffer";xhr.send(null);return new Uint8Array(xhr.response)}}readAsync=url=>{if(isFileURI(url)){return new Promise((resolve,reject)=>{var xhr=new XMLHttpRequest;xhr.open("GET",url,true);xhr.responseType="arraybuffer";xhr.onload=()=>{if(xhr.status==200||xhr.status==0&&xhr.response){resolve(xhr.response);return}reject(xhr.status)};xhr.onerror=reject;xhr.send(null)})}return fetch(url,{credentials:"same-origin"}).then(response=>{if(response.ok){return response.arrayBuffer()}return Promise.reject(new Error(response.status+" : "+response.url))})}}}else{}var out=Module["print"]||console.log.bind(console);var err=Module["printErr"]||console.error.bind(console);Object.assign(Module,moduleOverrides);moduleOverrides=null;if(Module["arguments"])arguments_=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];var wasmBinary=Module["wasmBinary"];var wasmMemory;var ABORT=false;var EXITSTATUS;var HEAP8,HEAPU8,HEAP16,HEAPU16,HEAP32,HEAPU32,HEAPF32,HEAPF64;function updateMemoryViews(){var b=wasmMemory.buffer;Module["HEAP8"]=HEAP8=new Int8Array(b);Module["HEAP16"]=HEAP16=new Int16Array(b);Module["HEAPU8"]=HEAPU8=new Uint8Array(b);Module["HEAPU16"]=HEAPU16=new Uint16Array(b);Module["HEAP32"]=HEAP32=new Int32Array(b);Module["HEAPU32"]=HEAPU32=new Uint32Array(b);Module["HEAPF32"]=HEAPF32=new Float32Array(b);Module["HEAPF64"]=HEAPF64=new Float64Array(b)}var __ATPRERUN__=[];var __ATINIT__=[];var __ATMAIN__=[];var __ATPOSTRUN__=[];var runtimeInitialized=false;function preRun(){if(Module["preRun"]){if(typeof Module["preRun"]=="function")Module["preRun"]=[Module["preRun"]];while(Module["preRun"].length){addOnPreRun(Module["preRun"].shift())}}callRuntimeCallbacks(__ATPRERUN__)}function initRuntime(){runtimeInitialized=true;callRuntimeCallbacks(__ATINIT__)}function preMain(){callRuntimeCallbacks(__ATMAIN__)}function postRun(){if(Module["postRun"]){if(typeof Module["postRun"]=="function")Module["postRun"]=[Module["postRun"]];while(Module["postRun"].length){addOnPostRun(Module["postRun"].shift())}}callRuntimeCallbacks(__ATPOSTRUN__)}function addOnPreRun(cb){__ATPRERUN__.unshift(cb)}function addOnInit(cb){__ATINIT__.unshift(cb)}function addOnPostRun(cb){__ATPOSTRUN__.unshift(cb)}var runDependencies=0;var runDependencyWatcher=null;var dependenciesFulfilled=null;function addRunDependency(id){runDependencies++;Module["monitorRunDependencies"]?.(runDependencies)}function removeRunDependency(id){runDependencies--;Module["monitorRunDependencies"]?.(runDependencies);if(runDependencies==0){if(runDependencyWatcher!==null){clearInterval(runDependencyWatcher);runDependencyWatcher=null}if(dependenciesFulfilled){var callback=dependenciesFulfilled;dependenciesFulfilled=null;callback()}}}function abort(what){Module["onAbort"]?.(what);what="Aborted("+what+")";err(what);ABORT=true;what+=". Build with -sASSERTIONS for more info.";var e=new WebAssembly.RuntimeError(what);throw e}var dataURIPrefix="data:application/octet-stream;base64,";var isDataURI=filename=>filename.startsWith(dataURIPrefix);var isFileURI=filename=>filename.startsWith("file://");function findWasmBinary(){var f="loader.wasm";if(!isDataURI(f)){return locateFile(f)}return f}var wasmBinaryFile;function getBinarySync(file){if(file==wasmBinaryFile&&wasmBinary){return new Uint8Array(wasmBinary)}if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}function getBinaryPromise(binaryFile){if(!wasmBinary){return readAsync(binaryFile).then(response=>new Uint8Array(response),()=>getBinarySync(binaryFile))}return Promise.resolve().then(()=>getBinarySync(binaryFile))}function instantiateArrayBuffer(binaryFile,imports,receiver){return getBinaryPromise(binaryFile).then(binary=>WebAssembly.instantiate(binary,imports)).then(receiver,reason=>{err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)})}function instantiateAsync(binary,binaryFile,imports,callback){if(!binary&&typeof WebAssembly.instantiateStreaming=="function"&&!isDataURI(binaryFile)&&!isFileURI(binaryFile)&&!ENVIRONMENT_IS_NODE&&typeof fetch=="function"){return fetch(binaryFile,{credentials:"same-origin"}).then(response=>{var result=WebAssembly.instantiateStreaming(response,imports);return result.then(callback,function(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation");return instantiateArrayBuffer(binaryFile,imports,callback)})})}return instantiateArrayBuffer(binaryFile,imports,callback)}function getWasmImports(){return{a:wasmImports}}function createWasm(){function receiveInstance(instance,module){wasmExports=instance.exports;wasmMemory=wasmExports["o"];updateMemoryViews();addOnInit(wasmExports["p"]);removeRunDependency("wasm-instantiate");return wasmExports}addRunDependency("wasm-instantiate");function receiveInstantiationResult(result){receiveInstance(result["instance"])}var info=getWasmImports();if(Module["instantiateWasm"]){try{return Module["instantiateWasm"](info,receiveInstance)}catch(e){err(`Module.instantiateWasm callback failed with error: ${e}`);return false}}wasmBinaryFile??=findWasmBinary();instantiateAsync(wasmBinary,wasmBinaryFile,info,receiveInstantiationResult);return{}}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var noExitRuntime=Module["noExitRuntime"]||true;var __emscripten_memcpy_js=(dest,src,num)=>HEAPU8.copyWithin(dest,src,src+num);var UTF8Decoder=typeof TextDecoder!="undefined"?new TextDecoder:undefined;var UTF8ArrayToString=(heapOrArray,idx=0,maxBytesToRead=NaN)=>{var endIdx=idx+maxBytesToRead;var endPtr=idx;while(heapOrArray[endPtr]&&!(endPtr>=endIdx))++endPtr;if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx<endPtr){var u0=heapOrArray[idx++];if(!(u0&128)){str+=String.fromCharCode(u0);continue}var u1=heapOrArray[idx++]&63;if((u0&224)==192){str+=String.fromCharCode((u0&31)<<6|u1);continue}var u2=heapOrArray[idx++]&63;if((u0&240)==224){u0=(u0&15)<<12|u1<<6|u2}else{u0=(u0&7)<<18|u1<<12|u2<<6|heapOrArray[idx++]&63}if(u0<65536){str+=String.fromCharCode(u0)}else{var ch=u0-65536;str+=String.fromCharCode(55296|ch>>10,56320|ch&1023)}}return str};var UTF8ToString=(ptr,maxBytesToRead)=>ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead):"";function _dbgErr(msg){console.error("LoaderMain: [ERROR] "+UTF8ToString(msg))}function _dbgLog(msg){console.log("LoaderMain: [INFO] "+UTF8ToString(msg))}var getHeapMax=()=>67108864;var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var growMemory=size=>{var b=wasmMemory.buffer;var pages=(size-b.byteLength+65535)/65536|0;try{wasmMemory.grow(pages);updateMemoryViews();return 1}catch(e){}};var _emscripten_resize_heap=requestedSize=>{var oldSize=HEAPU8.length;requestedSize>>>=0;var maxHeapSize=getHeapMax();if(requestedSize>maxHeapSize){return false}for(var cutDown=1;cutDown<=4;cutDown*=2){var overGrownHeapSize=oldSize*(1+.2/cutDown);overGrownHeapSize=Math.min(overGrownHeapSize,requestedSize+100663296);var newSize=Math.min(maxHeapSize,alignMemory(Math.max(requestedSize,overGrownHeapSize),65536));var replacement=growMemory(newSize);if(replacement){return true}}return false};function _getEPWLength(){return epwFile.byteLength}function _getJSPISupported(){return typeof WebAssembly.Suspending!=="undefined"}function _initEPWStringResult(off,len){const id=results.length;results.push(UTF8Decoder.decode(new Uint8Array(epwFile,off,len)));return id}function _initResult(bufLen){const id=results.length;results.push(new Uint8Array(bufLen));return id}function _memcpyFromEPW(dest,off,len){HEAPU8.set(new Uint8Array(epwFile,off,len),dest)}function _memcpyFromEPWToResult(bufId,dest,off,len){results[bufId].set(new Uint8Array(epwFile,off,len),dest)}function _memcpyToResult(bufId,src,off,len){results[bufId].set(new Uint8Array(HEAPU8.buffer,src,len),off)}function _resultFailed(msg){const parentElement=createCrashParentElement();const messageContainer=document.createElement("div");messageContainer.setAttribute("style","z-index:100;position:absolute;top:10%;left:10%;right:10%;bottom:10%;background-color:white;border:2px solid #cccccc;overflow-x:hidden;overflow-y:scroll;");messageContainer.classList.add("_eaglercraftX_loader_failed_container");const failMsg=UTF8ToString(msg);console.error("LoaderMain: [FAILED] "+failMsg);const failureMsgElement=document.createElement("h2");failureMsgElement.style.color="#AA0000";failureMsgElement.style.padding="25px";failureMsgElement.style.fontFamily="sans-serif";failureMsgElement.style["marginBlock"]="0px";failureMsgElement.appendChild(document.createTextNode(failMsg));messageContainer.appendChild(failureMsgElement);const failureMsgElement2=document.createElement("h4");failureMsgElement2.style.color="#AA0000";failureMsgElement2.style.padding="25px";failureMsgElement2.style.fontFamily="sans-serif";failureMsgElement2.style["marginBlock"]="0px";failureMsgElement2.appendChild(document.createTextNode("Try again later"));messageContainer.appendChild(failureMsgElement2);parentElement.appendChild(messageContainer)}function _resultJSPIUnsupported(result){const idx=result>>2;const crashImgData=results[HEAP32[idx]];const crashImgMIME=results[HEAP32[idx+1]];const crashImg=crashImgData?URL.createObjectURL(new Blob([crashImgData],{type:crashImgMIME||"image/png"})):null;const markupData=results[HEAP32[idx+2]];const markup=markupData?UTF8Decoder.decode(markupData):"<h1>Failed to load error screen</h1>";const parentElement=createCrashParentElement();const img=document.createElement("img");img.setAttribute("style","z-index:100;position:absolute;top:10px;left:calc(50% - 151px);");img.src=crashImg;parentElement.appendChild(img);const iframeContainer=document.createElement("div");iframeContainer.setAttribute("style","z-index:100;position:absolute;top:135px;left:10%;right:10%;bottom:50px;background-color:white;border:2px solid #cccccc;");iframeContainer.classList.add("_eaglercraftX_jspi_unsupported_container");const iframe=document.createElement("iframe");iframe.classList.add("_eaglercraftX_jspi_unsupported_frame");iframe.setAttribute("style","border:none;width:100%;height:100%;");iframe.srcdoc=markup;iframeContainer.appendChild(iframe);parentElement.appendChild(iframeContainer)}function _resultSuccess(result){const idx=result>>2;const eagRuntimeJSURL=URL.createObjectURL(new Blob([results[HEAP32[idx]]],{type:"text/javascript;charset=utf-8"}));const classesWASMURL=URL.createObjectURL(new Blob([results[HEAP32[idx+1]]],{type:"application/wasm"}));const classesDeobfTEADBGURL=URL.createObjectURL(new Blob([results[HEAP32[idx+2]]],{type:"application/octet-stream"}));const classesDeobfWASMURL=URL.createObjectURL(new Blob([results[HEAP32[idx+3]]],{type:"application/wasm"}));const pressAnyKey=URL.createObjectURL(new Blob([results[HEAP32[idx+4]]],{type:results[HEAP32[idx+5]]}));const crashImg=URL.createObjectURL(new Blob([results[HEAP32[idx+6]]],{type:results[HEAP32[idx+7]]}));const faviconImg=URL.createObjectURL(new Blob([results[HEAP32[idx+8]]],{type:results[HEAP32[idx+9]]}));const numEPKs=HEAP32[idx+10];const epkFiles=new Array(numEPKs);for(var i=0,j;i<numEPKs;++i){j=idx+11+i*3;epkFiles[i]={data:results[HEAP32[j]],name:results[HEAP32[j+1]],path:results[HEAP32[j+2]]}}results.length=0;window.__eaglercraftXLoaderContext={getEaglercraftXOpts:function(){return optsObj},getEagRuntimeJSURL:function(){return eagRuntimeJSURL},getClassesWASMURL:function(){return classesWASMURL},getClassesDeobfWASMURL:function(){return classesDeobfWASMURL},getClassesTEADBGURL:function(){return classesDeobfTEADBGURL},getEPKFiles:function(){return epkFiles},getRootElement:function(){return rootElement},getMainArgs:function(){return[]},getImageURL:function(idx){switch(idx){case 0:return splashURL;case 1:return pressAnyKey;case 2:return crashImg;case 3:return faviconImg;default:return null}},runMain:function(fn){setTimeout(fn,10)}};const scriptElement=document.createElement("script");scriptElement.type="text/javascript";scriptElement.src=eagRuntimeJSURL;document.head.appendChild(scriptElement)}var runtimeKeepaliveCounter=0;var keepRuntimeAlive=()=>noExitRuntime||runtimeKeepaliveCounter>0;var _proc_exit=code=>{EXITSTATUS=code;if(!keepRuntimeAlive()){Module["onExit"]?.(code);ABORT=true}quit_(code,new ExitStatus(code))};var exitJS=(status,implicit)=>{EXITSTATUS=status;_proc_exit(status)};var handleException=e=>{if(e instanceof ExitStatus||e=="unwind"){return EXITSTATUS}quit_(1,e)};var lengthBytesUTF8=str=>{var len=0;for(var i=0;i<str.length;++i){var c=str.charCodeAt(i);if(c<=127){len++}else if(c<=2047){len+=2}else if(c>=55296&&c<=57343){len+=4;++i}else{len+=3}}return len};var stringToUTF8Array=(str,heap,outIdx,maxBytesToWrite)=>{if(!(maxBytesToWrite>0))return 0;var startIdx=outIdx;var endIdx=outIdx+maxBytesToWrite-1;for(var i=0;i<str.length;++i){var u=str.charCodeAt(i);if(u>=55296&&u<=57343){var u1=str.charCodeAt(++i);u=65536+((u&1023)<<10)|u1&1023}if(u<=127){if(outIdx>=endIdx)break;heap[outIdx++]=u}else if(u<=2047){if(outIdx+1>=endIdx)break;heap[outIdx++]=192|u>>6;heap[outIdx++]=128|u&63}else if(u<=65535){if(outIdx+2>=endIdx)break;heap[outIdx++]=224|u>>12;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}else{if(outIdx+3>=endIdx)break;heap[outIdx++]=240|u>>18;heap[outIdx++]=128|u>>12&63;heap[outIdx++]=128|u>>6&63;heap[outIdx++]=128|u&63}}heap[outIdx]=0;return outIdx-startIdx};var stringToUTF8=(str,outPtr,maxBytesToWrite)=>stringToUTF8Array(str,HEAPU8,outPtr,maxBytesToWrite);var stackAlloc=sz=>__emscripten_stack_alloc(sz);var stringToUTF8OnStack=str=>{var size=lengthBytesUTF8(str)+1;var ret=stackAlloc(size);stringToUTF8(str,ret,size);return ret};var wasmImports={k:__emscripten_memcpy_js,c:_dbgErr,b:_dbgLog,j:_emscripten_resize_heap,n:_getEPWLength,i:_getJSPISupported,f:_initEPWStringResult,e:_initResult,d:_memcpyFromEPW,g:_memcpyFromEPWToResult,l:_memcpyToResult,a:_resultFailed,h:_resultJSPIUnsupported,m:_resultSuccess};var wasmExports=createWasm();var ___wasm_call_ctors=()=>(___wasm_call_ctors=wasmExports["p"])();var _main=Module["_main"]=(a0,a1)=>(_main=Module["_main"]=wasmExports["q"])(a0,a1);var __emscripten_stack_alloc=a0=>(__emscripten_stack_alloc=wasmExports["s"])(a0);var calledRun;dependenciesFulfilled=function runCaller(){if(!calledRun)run();if(!calledRun)dependenciesFulfilled=runCaller};function callMain(args=[]){var entryFunction=_main;args.unshift(thisProgram);var argc=args.length;var argv=stackAlloc((argc+1)*4);var argv_ptr=argv;args.forEach(arg=>{HEAPU32[argv_ptr>>2]=stringToUTF8OnStack(arg);argv_ptr+=4});HEAPU32[argv_ptr>>2]=0;try{var ret=entryFunction(argc,argv);exitJS(ret,true);return ret}catch(e){return handleException(e)}}function run(args=arguments_){if(runDependencies>0){return}preRun();if(runDependencies>0){return}function doRun(){if(calledRun)return;calledRun=true;Module["calledRun"]=true;if(ABORT)return;initRuntime();preMain();Module["onRuntimeInitialized"]?.();if(shouldRunNow)callMain(args);postRun()}if(Module["setStatus"]){Module["setStatus"]("Running...");setTimeout(()=>{setTimeout(()=>Module["setStatus"](""),1);doRun()},1)}else{doRun()}}if(Module["preInit"]){if(typeof Module["preInit"]=="function")Module["preInit"]=[Module["preInit"]];while(Module["preInit"].length>0){Module["preInit"].pop()()}}var shouldRunNow=true;if(Module["noInitialRun"])shouldRunNow=false;run();