diff --git a/README.md b/README.md
index 10ccba7..78b7d4c 100644
--- a/README.md
+++ b/README.md
@@ -16,8 +16,8 @@ Hackdex is a community hub for discovering and sharing Pokémon romhack patches.
## Core features
- **Discover**: curated hacks with screenshots, tags, versions, and summaries
-- **Submit**: metadata, screenshots, social links, and a BPS patch file
-- **Patch in the browser**: Powered by [RomPatcher.js](https://github.com/marcrobledo/RomPatcher.js); linked base roms stay on the user's device
+- **Submit**: metadata, screenshots, social links, and a `.bps` or `.xdelta` patch file
+- **Patch in the browser**: BPS via [RomPatcher.js](https://github.com/marcrobledo/RomPatcher.js); xdelta (VCDIFF) via a WASM build of [xdelta3](https://github.com/jmacd/xdelta) with glue from the Hackdex fork of [xdelta-wasm](https://github.com/Hackdex-App/xdelta-wasm) (forked from [kotcrab/xdelta-wasm](https://github.com/kotcrab/xdelta-wasm); statically linked [XZ Utils](https://tukaani.org/xz/) liblzma); linked base roms stay on the user's device
- **Safe delivery**: public urls for cover images, short-lived signed URLs for patch downloads and other assets; no rom storage required
## Tech stack
@@ -25,7 +25,7 @@ Hackdex is a community hub for discovering and sharing Pokémon romhack patches.
- Next.js 15 (App Router), TypeScript, React 19, Tailwind CSS 4
- Supabase (Postgres, Auth, Storage) for data, auth, and cover images
- S3-compatible object storage (Minio locally or preferred provider) for patch files (`patches` bucket)
-- In-browser patching with RomPatcher.js; local persistence with IndexedDB and the File System Access API
+- In-browser patching with RomPatcher.js and xdelta3 WASM; local persistence with IndexedDB and the File System Access API
## High-level architecture
diff --git a/docs/xdelta-wasm.md b/docs/xdelta-wasm.md
new file mode 100644
index 0000000..e14d781
--- /dev/null
+++ b/docs/xdelta-wasm.md
@@ -0,0 +1,69 @@
+# Building and vendoring xdelta WASM
+
+Hackdex patches xdelta (VCDIFF) files in the browser using a WebAssembly build of [xdelta3](https://github.com/jmacd/xdelta). That binary is **not** built inside this repo. You build it from a local checkout of the Hackdex fork of [xdelta-wasm](https://github.com/Hackdex-App/xdelta-wasm) (forked from [kotcrab/xdelta-wasm](https://github.com/kotcrab/xdelta-wasm)), then copy two artifacts into `public/xdelta/`.
+
+Use this guide when you need to rebuild or update those artifacts.
+
+---
+
+## Prerequisites
+
+- A local checkout of [Hackdex-App/xdelta-wasm](https://github.com/Hackdex-App/xdelta-wasm).
+- [Emscripten](https://emscripten.org) (`emcc` 6.x tested). On macOS: `brew install emscripten`. Otherwise follow the [emsdk install docs](https://emscripten.org/docs/getting_started/downloads.html).
+- After cloning xdelta-wasm, initialize the jmacd/xdelta submodule:
+
+```bash
+git submodule update --init
+```
+
+This populates `native/xdelta`.
+
+---
+
+## One-time setup (XZ / liblzma)
+
+Secondary LZMA compression (`xdelta3 -S lzma`) needs static liblzma. Run this if `native/xz/` is missing:
+
+```bash
+./native/build-xz.sh
+```
+
+That downloads XZ Utils and builds it with `emconfigure` / `emmake`.
+
+---
+
+## Building
+
+From the xdelta-wasm checkout root:
+
+```bash
+./native/build.sh
+```
+
+This compiles `native/xdelta/xdelta3/xdelta3.c` and `native/xdelta3-wasm.c`, links liblzma, and writes:
+
+- `public/xdelta3.js` (ES6 module)
+- `public/xdelta3.wasm` (Companion WASM binary)
+
+---
+
+## Vendoring into Hackdex
+
+Copy **only** those two files into this repo (overwrite existing):
+
+```bash
+cp public/xdelta3.js public/xdelta3.wasm \
+ /path/to/hackdex-website/public/xdelta/
+```
+
+Do **not** overwrite these Hackdex-owned files in `public/xdelta/`:
+
+- `xdelta3.worker.js`: Hackdex worker (protocol differs from upstream)
+- `LICENSE-xdelta3.txt`
+- `NOTICE.txt`
+
+---
+
+## Licensing
+
+See `public/xdelta/LICENSE-xdelta3.txt` and `public/xdelta/NOTICE.txt`.
\ No newline at end of file
diff --git a/public/xdelta/LICENSE-xdelta3.txt b/public/xdelta/LICENSE-xdelta3.txt
new file mode 100644
index 0000000..7a77415
--- /dev/null
+++ b/public/xdelta/LICENSE-xdelta3.txt
@@ -0,0 +1,176 @@
+Apache License
+Version 2.0, January 2004
+http://www.apache.org/licenses/
+
+TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
+
+1. Definitions.
+
+"License" shall mean the terms and conditions for use, reproduction,
+and distribution as defined by Sections 1 through 9 of this document.
+
+"Licensor" shall mean the copyright owner or entity authorized by
+the copyright owner that is granting the License.
+
+"Legal Entity" shall mean the union of the acting entity and all
+other entities that control, are controlled by, or are under common
+control with that entity. For the purposes of this definition,
+"control" means (i) the power, direct or indirect, to cause the
+direction or management of such entity, whether by contract or
+otherwise, or (ii) ownership of fifty percent (50%) or more of the
+outstanding shares, or (iii) beneficial ownership of such entity.
+
+"You" (or "Your") shall mean an individual or Legal Entity
+exercising permissions granted by this License.
+
+"Source" form shall mean the preferred form for making modifications,
+including but not limited to software source code, documentation
+source, and configuration files.
+
+"Object" form shall mean any form resulting from mechanical
+transformation or translation of a Source form, including but
+not limited to compiled object code, generated documentation,
+and conversions to other media types.
+
+"Work" shall mean the work of authorship, whether in Source or
+Object form, made available under the License, as indicated by a
+copyright notice that is included in or attached to the work
+(an example is provided in the Appendix below).
+
+"Derivative Works" shall mean any work, whether in Source or Object
+form, that is based on (or derived from) the Work and for which the
+editorial revisions, annotations, elaborations, or other modifications
+represent, as a whole, an original work of authorship. For the purposes
+of this License, Derivative Works shall not include works that remain
+separable from, or merely link (or bind by name) to the interfaces of,
+the Work and Derivative Works thereof.
+
+"Contribution" shall mean any work of authorship, including
+the original version of the Work and any modifications or additions
+to that Work or Derivative Works thereof, that is intentionally
+submitted to Licensor for inclusion in the Work by the copyright owner
+or by an individual or Legal Entity authorized to submit on behalf of
+the copyright owner. For the purposes of this definition, "submitted"
+means any form of electronic, verbal, or written communication sent
+to the Licensor or its representatives, including but not limited to
+communication on electronic mailing lists, source code control systems,
+and issue tracking systems that are managed by, or on behalf of, the
+Licensor for the purpose of discussing and improving the Work, but
+excluding communication that is conspicuously marked or otherwise
+designated in writing by the copyright owner as "Not a Contribution."
+
+"Contributor" shall mean Licensor and any individual or Legal Entity
+on behalf of whom a Contribution has been received by Licensor and
+subsequently incorporated within the Work.
+
+2. Grant of Copyright License. Subject to the terms and conditions of
+this License, each Contributor hereby grants to You a perpetual,
+worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+copyright license to reproduce, prepare Derivative Works of,
+publicly display, publicly perform, sublicense, and distribute the
+Work and such Derivative Works in Source or Object form.
+
+3. Grant of Patent License. Subject to the terms and conditions of
+this License, each Contributor hereby grants to You a perpetual,
+worldwide, non-exclusive, no-charge, royalty-free, irrevocable
+(except as stated in this section) patent license to make, have made,
+use, offer to sell, sell, import, and otherwise transfer the Work,
+where such license applies only to those patent claims licensable
+by such Contributor that are necessarily infringed by their
+Contribution(s) alone or by combination of their Contribution(s)
+with the Work to which such Contribution(s) was submitted. If You
+institute patent litigation against any entity (including a
+cross-claim or counterclaim in a lawsuit) alleging that the Work
+or a Contribution incorporated within the Work constitutes direct
+or contributory patent infringement, then any patent licenses
+granted to You under this License for that Work shall terminate
+as of the date such litigation is filed.
+
+4. Redistribution. You may reproduce and distribute copies of the
+Work or Derivative Works thereof in any medium, with or without
+modifications, and in Source or Object form, provided that You
+meet the following conditions:
+
+(a) You must give any other recipients of the Work or
+Derivative Works a copy of this License; and
+
+(b) You must cause any modified files to carry prominent notices
+stating that You changed the files; and
+
+(c) You must retain, in the Source form of any Derivative Works
+that You distribute, all copyright, patent, trademark, and
+attribution notices from the Source form of the Work,
+excluding those notices that do not pertain to any part of
+the Derivative Works; and
+
+(d) If the Work includes a "NOTICE" text file as part of its
+distribution, then any Derivative Works that You distribute must
+include a readable copy of the attribution notices contained
+within such NOTICE file, excluding those notices that do not
+pertain to any part of the Derivative Works, in at least one
+of the following places: within a NOTICE text file distributed
+as part of the Derivative Works; within the Source form or
+documentation, if provided along with the Derivative Works; or,
+within a display generated by the Derivative Works, if and
+wherever such third-party notices normally appear. The contents
+of the NOTICE file are for informational purposes only and
+do not modify the License. You may add Your own attribution
+notices within Derivative Works that You distribute, alongside
+or as an addendum to the NOTICE text from the Work, provided
+that such additional attribution notices cannot be construed
+as modifying the License.
+
+You may add Your own copyright statement to Your modifications and
+may provide additional or different license terms and conditions
+for use, reproduction, or distribution of Your modifications, or
+for any such Derivative Works as a whole, provided Your use,
+reproduction, and distribution of the Work otherwise complies with
+the conditions stated in this License.
+
+5. Submission of Contributions. Unless You explicitly state otherwise,
+any Contribution intentionally submitted for inclusion in the Work
+by You to the Licensor shall be under the terms and conditions of
+this License, without any additional terms or conditions.
+Notwithstanding the above, nothing herein shall supersede or modify
+the terms of any separate license agreement you may have executed
+with Licensor regarding such Contributions.
+
+6. Trademarks. This License does not grant permission to use the trade
+names, trademarks, service marks, or product names of the Licensor,
+except as required for reasonable and customary use in describing the
+origin of the Work and reproducing the content of the NOTICE file.
+
+7. Disclaimer of Warranty. Unless required by applicable law or
+agreed to in writing, Licensor provides the Work (and each
+Contributor provides its Contributions) on an "AS IS" BASIS,
+WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
+implied, including, without limitation, any warranties or conditions
+of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
+PARTICULAR PURPOSE. You are solely responsible for determining the
+appropriateness of using or redistributing the Work and assume any
+risks associated with Your exercise of permissions under this License.
+
+8. Limitation of Liability. In no event and under no legal theory,
+whether in tort (including negligence), contract, or otherwise,
+unless required by applicable law (such as deliberate and grossly
+negligent acts) or agreed to in writing, shall any Contributor be
+liable to You for damages, including any direct, indirect, special,
+incidental, or consequential damages of any character arising as a
+result of this License or out of the use or inability to use the
+Work (including but not limited to damages for loss of goodwill,
+work stoppage, computer failure or malfunction, or any and all
+other commercial damages or losses), even if such Contributor
+has been advised of the possibility of such damages.
+
+9. Accepting Warranty or Additional Liability. While redistributing
+the Work or Derivative Works thereof, You may choose to offer,
+and charge a fee for, acceptance of support, warranty, indemnity,
+or other liability obligations and/or rights consistent with this
+License. However, in accepting such obligations, You may act only
+on Your own behalf and on Your sole responsibility, not on behalf
+of any other Contributor, and only if You agree to indemnify,
+defend, and hold each Contributor harmless for any liability
+incurred by, or claims asserted against, such Contributor by reason
+of your accepting any such warranty or additional liability.
+
+END OF TERMS AND CONDITIONS
diff --git a/public/xdelta/NOTICE.txt b/public/xdelta/NOTICE.txt
new file mode 100644
index 0000000..52d37cb
--- /dev/null
+++ b/public/xdelta/NOTICE.txt
@@ -0,0 +1,17 @@
+xdelta3.wasm and xdelta3.js
+===========================
+
+These artifacts are built from xdelta3
+(https://github.com/jmacd/xdelta), Copyright Joshua MacDonald,
+licensed under the Apache License, Version 2.0. See LICENSE-xdelta3.txt.
+
+They include glue code from the Hackdex fork of xdelta-wasm
+(https://github.com/Hackdex-App/xdelta-wasm), forked from
+kotcrab/xdelta-wasm (https://github.com/kotcrab/xdelta-wasm), also
+licensed under Apache-2.0. That glue code has been modified for
+Hackdex (encoder support and checksum-presence reporting). Per
+Apache-2.0 section 4(b), this NOTICE states that modifications were
+made.
+
+The build statically links liblzma from XZ Utils
+(https://tukaani.org/xz/), which is 0BSD / public domain.
diff --git a/public/xdelta/xdelta3.js b/public/xdelta/xdelta3.js
new file mode 100644
index 0000000..d885e3a
--- /dev/null
+++ b/public/xdelta/xdelta3.js
@@ -0,0 +1,2 @@
+async function createXdelta3Module(moduleArg={}){var Module=moduleArg;var ENVIRONMENT_IS_WEB=false;var ENVIRONMENT_IS_WORKER=true;var programArgs=[];var thisProgram="./this.program";var quit_=(status,toThrow)=>{throw toThrow};var _scriptName=import.meta.url;var scriptDirectory="";function locateFile(path){if(Module["locateFile"]){return Module["locateFile"](path,scriptDirectory)}return scriptDirectory+path}var readAsync,readBinary;if(ENVIRONMENT_IS_WEB||ENVIRONMENT_IS_WORKER){try{scriptDirectory=new URL(".",_scriptName).href}catch{}{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=async url=>{var response=await fetch(url,{credentials:"same-origin"});if(response.ok){return response.arrayBuffer()}throw new Error(response.status+" : "+response.url)}}}else{}var out=console.log.bind(console);var err=console.error.bind(console);var wasmBinary;var ABORT=false;var EXITSTATUS;class EmscriptenEH{}class EmscriptenSjLj extends EmscriptenEH{}var runtimeInitialized=false;function getMemoryBuffer(){return wasmMemory.buffer}function updateMemoryViews(){if(HEAP8?.buffer?.resizable)return;var b=getMemoryBuffer();Module["HEAP8"]=HEAP8=new Int8Array(b);HEAP16=new Int16Array(b);HEAPU8=new Uint8Array(b);HEAPU16=new Uint16Array(b);HEAP32=new Int32Array(b);HEAPU32=new Uint32Array(b);HEAPF32=new Float32Array(b);HEAPF64=new Float64Array(b);HEAP64=new BigInt64Array(b);HEAPU64=new BigUint64Array(b)}function preRun(){var preRun=Module["preRun"];if(preRun){if(typeof preRun=="function")preRun=[preRun];onPreRuns.push(...preRun)}callRuntimeCallbacks(onPreRuns)}function initRuntime(){runtimeInitialized=true;wasmExports["__wasm_call_ctors"]()}function postRun(){var postRun=Module["postRun"];if(postRun){if(typeof postRun=="function")postRun=[postRun];onPostRuns.push(...postRun)}callRuntimeCallbacks(onPostRuns)}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 wasmBinaryFile;function findWasmBinary(){if(Module["locateFile"]){return locateFile("xdelta3.wasm")}return new URL("xdelta3.wasm",import.meta.url).href}function getBinarySync(file){if(readBinary){return readBinary(file)}throw"both async and sync fetching of the wasm failed"}async function getWasmBinary(binaryFile){if(!wasmBinary){try{var response=await readAsync(binaryFile);return new Uint8Array(response)}catch{}}return getBinarySync(binaryFile)}async function instantiateArrayBuffer(binaryFile,imports){try{var binary=await getWasmBinary(binaryFile);var instance=await WebAssembly.instantiate(binary,imports);return instance}catch(reason){err(`failed to asynchronously prepare wasm: ${reason}`);abort(reason)}}async function instantiateAsync(binary,binaryFile,imports){if(!binary){try{var response=fetch(binaryFile,{credentials:"same-origin"});var instantiationResult=await WebAssembly.instantiateStreaming(response,imports);return instantiationResult}catch(reason){err(`wasm streaming compile failed: ${reason}`);err("falling back to ArrayBuffer instantiation")}}return instantiateArrayBuffer(binaryFile,imports)}function getWasmImports(){var imports={env:wasmImports,wasi_snapshot_preview1:wasmImports};return imports}async function createWasm(){function receiveInstance(instance){wasmExports=instance.exports;assignWasmExports(wasmExports);updateMemoryViews();return wasmExports}function receiveInstantiationResult(result){return receiveInstance(result["instance"])}var info=getWasmImports();var instantiateWasm=Module["instantiateWasm"];if(instantiateWasm){return new Promise(resolve=>{instantiateWasm(info,inst=>resolve(receiveInstance(inst)))})}wasmBinaryFile??=findWasmBinary();var result=await instantiateAsync(wasmBinary,wasmBinaryFile,info);var exports=receiveInstantiationResult(result);return exports}class ExitStatus{name="ExitStatus";constructor(status){this.message=`Program terminated with exit(${status})`;this.status=status}}var HEAP16;var HEAP32;var HEAP64;var HEAP8;var HEAPF32;var HEAPF64;var HEAPU16;var HEAPU32;var HEAPU64;var HEAPU8;var callRuntimeCallbacks=callbacks=>{while(callbacks.length>0){callbacks.shift()(Module)}};var onPostRuns=[];var onPreRuns=[];var noExitRuntime=true;var readEmAsmArgsArray=[];var readEmAsmArgs=(sigPtr,buf)=>{readEmAsmArgsArray.length=0;var ch;while(ch=HEAPU8[sigPtr++]){var wide=ch!=105;wide&=ch!=112;buf+=wide&&buf%8?4:0;readEmAsmArgsArray.push(ch==112?HEAPU32[buf>>2]:ch==106?HEAP64[buf>>3]:ch==105?HEAP32[buf>>2]:HEAPF64[buf>>3]);buf+=wide?8:4}return readEmAsmArgsArray};var runEmAsmFunction=(code,sigPtr,argbuf)=>{var args=readEmAsmArgs(sigPtr,argbuf);return ASM_CONSTS[code](...args)};var _emscripten_asm_const_int=(code,sigPtr,argbuf)=>runEmAsmFunction(code,sigPtr,argbuf);var abortOnCannotGrowMemory=requestedSize=>{abort("OOM")};var getHeapMax=()=>2147483648;var alignMemory=(size,alignment)=>Math.ceil(size/alignment)*alignment;var growMemory=size=>{var oldHeapSize=wasmMemory.buffer.byteLength;var pages=(size-oldHeapSize+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){abortOnCannotGrowMemory(requestedSize)}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}}abortOnCannotGrowMemory(requestedSize)};var _fd_close=fd=>52;var INT53_MAX=9007199254740992;var INT53_MIN=-9007199254740992;var bigintToI53Checked=num=>numINT53_MAX?NaN:Number(num);function _fd_seek(fd,offset,whence,newOffset){offset=bigintToI53Checked(offset);return 70}var printCharBuffers=[null,[],[]];var UTF8Decoder=globalThis.TextDecoder&&new TextDecoder;var findStringEnd=(heapOrArray,idx,maxBytesToRead,ignoreNul)=>{var maxIdx=idx+maxBytesToRead;if(ignoreNul)return maxIdx;while(heapOrArray[idx]&&!(idx>=maxIdx))++idx;return idx};var UTF8ArrayToString=(heapOrArray,idx=0,maxBytesToRead,ignoreNul)=>{var endPtr=findStringEnd(heapOrArray,idx,maxBytesToRead,ignoreNul);if(endPtr-idx>16&&heapOrArray.buffer&&UTF8Decoder){return UTF8Decoder.decode(heapOrArray.subarray(idx,endPtr))}var str="";while(idx>10,56320|ch&1023)}}return str};var printChar=(stream,curr)=>{var buffer=printCharBuffers[stream];if(curr===0||curr===10){(stream===1?out:err)(UTF8ArrayToString(buffer));buffer.length=0}else{buffer.push(curr)}};var UTF8ToString=(ptr,maxBytesToRead,ignoreNul)=>ptr?UTF8ArrayToString(HEAPU8,ptr,maxBytesToRead,ignoreNul):"";var _fd_write=(fd,iov,iovcnt,pnum)=>{var num=0;for(var i=0;i>2];var len=HEAPU32[iov+4>>2];iov+=8;for(var j=0;j>2]=num;return 0};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=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=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;i++}}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};{if(Module["noExitRuntime"])noExitRuntime=Module["noExitRuntime"];if(Module["print"])out=Module["print"];if(Module["printErr"])err=Module["printErr"];if(Module["arguments"])programArgs=Module["arguments"];if(Module["thisProgram"])thisProgram=Module["thisProgram"];var preInit=Module["preInit"];if(preInit){if(typeof preInit=="function")Module["preInit"]=preInit=[preInit];while(preInit.length>0){preInit.shift()()}}}Module["callMain"]=callMain;Module["UTF8ToString"]=UTF8ToString;var ASM_CONSTS={30936:($0,$1,$2)=>Module.readSource($0,$1,$2),30978:($0,$1,$2)=>Module.readInput($0,$1,$2),31019:($0,$1)=>{Module.outputFile($0,$1)},31047:$0=>{Module.reportError($0)},31072:$0=>{Module.reportChecksums($0)}};var _main,__emscripten_stack_restore,__emscripten_stack_alloc,_emscripten_stack_get_current,memory,__indirect_function_table,wasmMemory;function assignWasmExports(wasmExports){_main=Module["_main"]=wasmExports["__main_argc_argv"];__emscripten_stack_restore=wasmExports["_emscripten_stack_restore"];__emscripten_stack_alloc=wasmExports["_emscripten_stack_alloc"];_emscripten_stack_get_current=wasmExports["emscripten_stack_get_current"];memory=wasmMemory=wasmExports["memory"];__indirect_function_table=wasmExports["__indirect_function_table"]}var wasmImports={emscripten_asm_const_int:_emscripten_asm_const_int,emscripten_resize_heap:_emscripten_resize_heap,fd_close:_fd_close,fd_seek:_fd_seek,fd_write:_fd_write};function callMain(args=[]){var entryFunction=_main;args.unshift(thisProgram);var argc=args.length;var argv=stackAlloc((argc+1)*4);var argv_ptr=argv;for(var arg of args){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)}}async function run(args=programArgs){preRun();var setStatus=Module["setStatus"];if(setStatus){setStatus("Running...");await new Promise(resolve=>setTimeout(resolve,1));setTimeout(setStatus,1,"")}if(ABORT)return;initRuntime();Module["onRuntimeInitialized"]?.();var noInitialRun=Module["noInitialRun"]||true;if(!noInitialRun)callMain(args);postRun()}var wasmExports;wasmExports=await createWasm();await run();
+;return Module}export default createXdelta3Module;
diff --git a/public/xdelta/xdelta3.wasm b/public/xdelta/xdelta3.wasm
new file mode 100755
index 0000000..680e599
Binary files /dev/null and b/public/xdelta/xdelta3.wasm differ
diff --git a/public/xdelta/xdelta3.worker.js b/public/xdelta/xdelta3.worker.js
new file mode 100644
index 0000000..c34b82b
--- /dev/null
+++ b/public/xdelta/xdelta3.worker.js
@@ -0,0 +1,133 @@
+import createXdelta3Module from './xdelta3.js'
+
+const bufferSize = 4 * 1024 * 1024
+const cacheSize = 32
+const PROGRESS_INTERVAL = 8 * 1024 * 1024
+
+let module = undefined
+const state = {
+ sourceFile: undefined,
+ inputFile: undefined,
+ errorMessage: undefined,
+ hasChecksums: null,
+ discardOutput: false,
+ bytesOut: 0,
+ bytesIn: 0,
+ lastProgressAt: 0,
+}
+
+// eslint-disable-next-line no-undef
+const reader = new FileReaderSync()
+
+function readSource(buffer, offset, size) {
+ return readFile(state.sourceFile, buffer, Number(offset), size)
+}
+
+function readInput(buffer, offset, size) {
+ const read = readFile(state.inputFile, buffer, Number(offset), size)
+ state.bytesIn += read
+ return read
+}
+
+function reportChecksums(hasChecksums) {
+ state.hasChecksums = hasChecksums ? true : false
+}
+
+function readFile(file, buffer, offset, size) {
+ const end = Math.min(file.size, offset + size)
+ const blob = file.slice(offset, end)
+ const read = end - offset
+ const data = reader.readAsArrayBuffer(blob)
+ module.HEAP8.set(new Uint8Array(data), buffer)
+ return read
+}
+
+function maybeProgress() {
+ if (state.bytesOut - state.lastProgressAt >= PROGRESS_INTERVAL) {
+ postMessage({
+ type: 'progress',
+ bytesOut: state.bytesOut,
+ bytesIn: state.bytesIn,
+ })
+ state.lastProgressAt = state.bytesOut
+ }
+}
+
+function outputFile(buffer, size) {
+ state.bytesOut += size
+ if (!state.discardOutput) {
+ const dataView = new Uint8Array(module.HEAP8.buffer, buffer, size)
+ const data = new Uint8Array(dataView)
+ postMessage({ type: 'chunk', bytes: data }, [data.buffer])
+ }
+ maybeProgress()
+}
+
+function reportError(msgPtr) {
+ state.errorMessage = module.UTF8ToString(msgPtr)
+}
+
+function postDone(ok, errorCode) {
+ const msg = {
+ type: 'done',
+ ok,
+ hasChecksums: state.hasChecksums,
+ }
+ if (errorCode !== undefined) {
+ msg.errorCode = errorCode
+ }
+ if (state.errorMessage) {
+ msg.errorMessage = state.errorMessage
+ }
+ postMessage(msg)
+}
+
+onmessage = async function (event) {
+ if (!event.data) {
+ return
+ }
+ const { command, mode, sourceFile, inputFile, disableChecksum, discardOutput } = event.data
+ if (command !== 'start') {
+ return
+ }
+
+ state.sourceFile = sourceFile
+ state.inputFile = inputFile
+ state.errorMessage = undefined
+ state.hasChecksums = null
+ state.discardOutput = !!discardOutput
+ state.bytesOut = 0
+ state.bytesIn = 0
+ state.lastProgressAt = 0
+
+ try {
+ module = await createXdelta3Module()
+ module.readInput = readInput
+ module.readSource = readSource
+ module.outputFile = outputFile
+ module.reportError = reportError
+ module.reportChecksums = reportChecksums
+
+ const result = module.callMain([
+ mode,
+ bufferSize.toString(),
+ cacheSize.toString(),
+ (!!disableChecksum).toString(),
+ // Known source size lets the encoder search the whole source for matches.
+ sourceFile.size.toString(),
+ ])
+
+ if (result !== 0) {
+ postDone(false, result)
+ } else {
+ postDone(true)
+ }
+ } catch (e) {
+ console.error(e)
+ if (!state.errorMessage && e && typeof e.message === 'string') {
+ state.errorMessage = e.message
+ }
+ postDone(false)
+ }
+ module = undefined
+}
diff --git a/src/app/faq/entries.md b/src/app/faq/entries.md
index 426a6b5..7d6700d 100644
--- a/src/app/faq/entries.md
+++ b/src/app/faq/entries.md
@@ -79,14 +79,12 @@ Only the original creator or a member of their team can submit the hack to Hackd
Account creation is required for submissions to preserve author control and attribution. This ensures your work is properly credited and you maintain control over your hack's listing. This also allows you to update your hack after submission.
### What format should I submit my hack in?
-We only accept BPS patch files, not complete ROMs. Hackdex utilizes a built-in patcher that users apply to their own legally obtained base ROMs. This helps keep the platform safer from potential legal issues.
+We accept `.bps` and `.xdelta` patch files, not complete ROMs. Hackdex utilizes a built-in patcher that users apply to their own legally obtained base ROMs. This helps keep the platform safer from potential legal issues. xdelta is the preferred format going forward; legacy BPS patches continue to work.
-A built-in patcher is also included in the submission form, so you also have the option to provide your modified ROM and the base ROM to generate the patch file automatically.
+A built-in patcher is also included in the submission form, so you also have the option to provide your modified ROM and the base ROM to generate a `.xdelta` patch file automatically.
-### Why only BPS patch files?
-The BPS format is the successor to the IPS and UPS formats, with the added benefit of including hash checksums for verification. This helps ensure that the patch file is linked to the correct base ROM. An incorrect base ROM will result in a corrupted game.
-
-There are also plans to add Xdelta support for NDS hacks in the future.
+### Why only BPS and Xdelta patch files?
+Both formats support checksum verification so the patch is linked to the correct base ROM. An incorrect base ROM will result in a corrupted game. BPS remains supported for existing hacks; new in-browser patch creation produces Xdelta files, which is the preferred format going forward.
### How does my hack gain visibility?
We highly recommend linking to your romhack's Hackdex page from PokéCommunity, Reddit, or other social media platforms. Doing so can help boost your hack's visibility and outrank those sketchy ROM sharing sites that steal many creators' hard work.
diff --git a/src/app/hack/[slug]/actions.ts b/src/app/hack/[slug]/actions.ts
index 29854a6..2105063 100644
--- a/src/app/hack/[slug]/actions.ts
+++ b/src/app/hack/[slug]/actions.ts
@@ -229,12 +229,21 @@ export async function getHackDownloads(slug: string): Promise {
return runner();
}
+type GetSignedPatchUrlResult = {
+ ok: true;
+ url: string;
+ format: Database["public"]["Enums"]["Patch Format"];
+} | {
+ ok: false;
+ error: string;
+};
+
export async function getSignedPatchUrl(
slug: string,
options?: {
patchId?: number;
}
-): Promise<{ ok: true; url: string } | { ok: false; error: string }> {
+): Promise {
const supabase = await createClient();
// Get user for permission check
@@ -282,7 +291,7 @@ export async function getSignedPatchUrl(
// Fetch patch info
const { data: patch, error: patchError } = await supabase
.from("patches")
- .select("id, bucket, filename, parent_hack, published, archived")
+ .select("id, bucket, filename, parent_hack, published, archived, format")
.eq("id", selectedPatchId)
.maybeSingle();
@@ -297,12 +306,12 @@ export async function getSignedPatchUrl(
try {
const workerUrl = buildPatchDownloadUrl(patch.filename);
if (workerUrl) {
- return { ok: true, url: workerUrl };
+ return { ok: true, url: workerUrl, format: patch.format };
}
const client = getMinioClient();
const bucket = patch.bucket || PATCHES_BUCKET;
const signedUrl = await client.presignedGetObject(bucket, patch.filename, 60 * 5);
- return { ok: true, url: signedUrl };
+ return { ok: true, url: signedUrl, format: patch.format };
} catch (error) {
console.error("Error signing patch URL:", error);
return { ok: false, error: "Failed to generate download URL" };
@@ -1010,11 +1019,12 @@ export async function confirmReuploadPatchVersion(
return { ok: false, error: "Patch not found" };
}
- // Update patch filename
+ // Update patch filename and format (derived from object key extension)
+ const format = objectKey.toLowerCase().endsWith(".xdelta") ? "xdelta" : "bps";
const serviceClient = await createServiceClient();
const { error: updateErr } = await serviceClient
.from("patches")
- .update({ filename: objectKey, updated_at: new Date().toISOString() })
+ .update({ filename: objectKey, format, updated_at: new Date().toISOString() })
.eq("id", patchId);
if (updateErr) return { ok: false, error: updateErr.message };
diff --git a/src/app/hack/[slug]/page.tsx b/src/app/hack/[slug]/page.tsx
index ca8fddb..011b5fd 100644
--- a/src/app/hack/[slug]/page.tsx
+++ b/src/app/hack/[slug]/page.tsx
@@ -598,7 +598,7 @@ export default async function HackDetail({ params }: HackDetailProps) {
using our built-in patcher.
- By pressing "Agree and Patch", your browser will download and apply the {hack.title} .bps patch file to your legally-obtained {baseRom?.name} ROM. The patched ROM will then be automatically downloaded.
+ By pressing "Agree and Patch", your browser will download and apply the {hack.title} patch file to your legally-obtained {baseRom?.name} ROM. The patched ROM will then be automatically downloaded.