Manic EMU is an all-in-one retro game emulator for iOS. It packs powerful features while keeping a clean, sleek UI and delivering buttery-smooth gameplay.
Swift
const BDF_MAGIC="BSDIFF40";function BDF(){this.records=[],this.patchedSize=0}"undefined"!=typeof module&&module.exports&&(module.exports=BDF),BDF.prototype.apply=function(e){var t=new BinFile(this.patchedSize);for(const r of this.records){for(const o of r.diff)t.writeU8(e.readU8()+o);t.writeBytes(r.extra),e.seek(e.offset+r.skip)}return t},BDF.MAGIC=BDF_MAGIC,BDF.fromFile=function(e){var t=new BDF;e.seek(8),e.littleEndian=!0;var r=e.readU64(),o=e.readU64();t.patchedSize=e.readU64();var l=e.readBytes(r),s=e.readBytes(o),f=e.readBytes(e.fileSize-e.offset),i=new BinFile(bz2.decompress(l));i.littleEndian=!0;for(var n=new BinFile(bz2.decompress(s)),a=new BinFile(bz2.decompress(f));!i.isEOF();){var h=i.readU64(),d=i.readU64(),u=i.readU64();u&1<<63&&(u=-(u&~(1<<63)));var c=n.readBytes(h),p=a.readBytes(d);t.records.push({diff:c,extra:p,skip:u})}return t};const bz2=function(){let e=[0,79764919,159529838,222504665,319059676,398814059,445009330,507990021,638119352,583659535,797628118,726387553,890018660,835552979,1015980042,944750013,1276238704,1221641927,1167319070,1095957929,1595256236,1540665371,1452775106,1381403509,1780037320,1859660671,1671105958,1733955601,2031960084,2111593891,1889500026,1952343757,2552477408,2632100695,2443283854,2506133561,2334638140,2414271883,2191915858,2254759653,3190512472,3135915759,3081330742,3009969537,2905550212,2850959411,2762807018,2691435357,3560074640,3505614887,3719321342,3648080713,3342211916,3287746299,3467911202,3396681109,4063920168,4143685023,4223187782,4286162673,3779000052,3858754371,3904687514,3967668269,881225847,809987520,1023691545,969234094,662832811,591600412,771767749,717299826,311336399,374308984,453813921,533576470,25881363,88864420,134795389,214552010,2023205639,2086057648,1897238633,1976864222,1804852699,1867694188,1645340341,1724971778,1587496639,1516133128,1461550545,1406951526,1302016099,1230646740,1142491917,1087903418,2896545431,2825181984,2770861561,2716262478,3215044683,3143675388,3055782693,3001194130,2326604591,2389456536,2200899649,2280525302,2578013683,2640855108,2418763421,2498394922,3769900519,3832873040,3912640137,3992402750,4088425275,4151408268,4197601365,4277358050,3334271071,3263032808,3476998961,3422541446,3585640067,3514407732,3694837229,3640369242,1762451694,1842216281,1619975040,1682949687,2047383090,2127137669,1938468188,2001449195,1325665622,1271206113,1183200824,1111960463,1543535498,1489069629,1434599652,1363369299,622672798,568075817,748617968,677256519,907627842,853037301,1067152940,995781531,51762726,131386257,177728840,240578815,269590778,349224269,429104020,491947555,4046411278,4126034873,4172115296,4234965207,3794477266,3874110821,3953728444,4016571915,3609705398,3555108353,3735388376,3664026991,3290680682,3236090077,3449943556,3378572211,3174993278,3120533705,3032266256,2961025959,2923101090,2868635157,2813903052,2742672763,2604032198,2683796849,2461293480,2524268063,2284983834,2364738477,2175806836,2238787779,1569362073,1498123566,1409854455,1355396672,1317987909,1246755826,1192025387,1137557660,2072149281,2135122070,1912620623,1992383480,1753615357,1816598090,1627664531,1707420964,295390185,358241886,404320391,483945776,43990325,106832002,186451547,266083308,932423249,861060070,1041341759,986742920,613929101,542559546,756411363,701822548,3316196985,3244833742,3425377559,3370778784,3601682597,3530312978,3744426955,3689838204,3819031489,3881883254,3928223919,4007849240,4037393693,4100235434,4180117107,4259748804,2310601993,2373574846,2151335527,2231098320,2596047829,2659030626,2470359227,2550115596,2947551409,2876312838,2788305887,2733848168,3165939309,3094707162,3040238851,2985771188],t=[0,1,3,7,15,31,63,127,255,511,1023,2047,4095,8191,16383,32767,65535,131071,262143,524287,1048575,2097151,4194303,8388607,16777215,33554431,67108863,134217727,268435455,536870911,1073741823,-2147483648];function r(e){let t=[];for(let r=0;r<e.length;r+=1)t.push([r,e[r]]);t.push([e.length,-1]);let r=[],o=t[0][0],l=t[0][1];for(let e=0;e<t.length;e+=1){let s=t[e][0],f=t[e][1];if(l)for(let e=o;e<s;e+=1)r.push({code:e,bits:l,symbol:void 0});if(o=s,l=f,-1===f)break}r.sort((e,t)=>e.bits-t.bits||e.code-t.code);let s,f=0,i=-1,n=[];for(let e=0;e<r.length;e+=1){let t=r[e];i+=1,t.bits!==f&&(i<<=t.bits-f,s=n[f=t.bits]={}),t.symbol=i,s[i]=t}return{table:r,fastAccess:n}}function o(e,t){if(t<0||t>=e.length)throw RangeError("Out of bound");let r=e.slice();e.sort((e,t)=>e-t);let o={};for(let t=e.length-1;t>=0;t-=1)o[e[t]]=t;let l=[];for(let t=0;t<e.length;t+=1)l.push(o[r[t]]++);let s,f=e[s=t],i=[];for(let t=1;t<e.length;t+=1){let t=e[s=l[s]];void 0===t?i.push(255):i.push(t)}return i.push(f),i.reverse(),i}let l={decompress:function(l,s=!1){let f=0,i=0,n=0,a=e=>{if(e>=32){let t=e>>1;return a(t)*(1<<t)+a(e-t)}for(;n<e;)i=(i<<8)+l[f],f+=1,n+=8;let r=t[e],o=i>>n-e&r;return n-=e,i&=~(r<<n),o};if(16986!==a(16))throw Error("Invalid magic");if(104!==a(8))throw Error("Invalid method");let h=a(8);if(!(h>=49&&h<=57))throw Error("Invalid blocksize");h-=48;let d=new Uint8Array(1.5*l.length),u=0,c=-1;for(;;){let h=a(48),p=0|a(32);if(54156738319193!==h){if(25779555029136===h){a(7&n);break}throw Error("Invalid bz2 blocktype")}{if(a(1))throw Error("do not support randomised");let h=a(24),b=[],g=a(16);for(let e=32768;e>0;e>>=1){if(!(g&e)){for(let e=0;e<16;e+=1)b.push(!1);continue}let t=a(16);for(let e=32768;e>0;e>>=1)b.push(!!(t&e))}let w=a(3);if(w<2||w>6)throw Error("Invalid number of huffman groups");let m=a(15),B=[],y=Array.from({length:w},(e,t)=>t);for(let e=0;e<m;e+=1){let e=0;for(;a(1);)if((e+=1)>=w)throw Error("MTF table out of range");let t=y[e];for(let t=e;t>0;y[t]=y[--t]);B.push(t),y[0]=t}let F=b.reduce((e,t)=>e+t,0)+2,v=[];for(let e=0;e<w;e+=1){let e=a(5),t=[];for(let r=0;r<F;r+=1){if(e<0||e>20)throw Error("Huffman group length outside range");for(;a(1);)e-=2*a(1)-1;t.push(e)}v.push(r(t))}let E=[];for(let e=0;e<b.length-1;e+=1)b[e]&&E.push(e);let k,z,A=0,U=0,D=0,I=0,C=[];for(;;){for(let e in(A-=1)<=0&&(A=50,U<=B.length&&(k=v[B[U]],U+=1)),k.fastAccess)if(Object.prototype.hasOwnProperty.call(k.fastAccess,e)&&(n<e&&(i=(i<<8)+l[f],f+=1,n+=8),z=k.fastAccess[e][i>>n-e])){i&=t[n-=e],z=z.code;break}if(z>=0&&z<=1)0===D&&(I=1),D+=I<<z,I<<=1;else{{let e=E[0];for(;D>0;D-=1)C.push(e)}if(z===F-1)break;{let e=E[z-1];for(let e=z-1;e>0;E[e]=E[--e]);E[0]=e,C.push(e)}}}let S=o(C,h),x=0;for(;x<S.length;){let t=S[x],r=1;if(x<S.length-4&&S[x+1]===t&&S[x+2]===t&&S[x+3]===t?(r=S[x+4]+4,x+=5):x+=1,u+r>=d.length){let e=d;(d=new Uint8Array(2*e.length)).set(e)}for(let o=0;o<r;o+=1)s&&(c=c<<8^e[255&(c>>24^t)]),d[u]=t,u+=1}if(s){let e=-1^c;if(e!==p)throw Error(`CRC mismatch: ${e} !== ${p}`);c=-1}}}return d.subarray(0,u)}};return l}();