@overlayed/app 0.18.2 → 0.18.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/index.js CHANGED
@@ -2,4 +2,4 @@ import{createRequire as e}from"node:module";import{Type as t,type as n}from"arkt
2
2
  `:`
3
3
  `)+n,i=r+1,r=e.indexOf(`
4
4
  `,i)}while(r!==-1);return a+=e.slice(i),a}const{stdout:Be,stderr:Ve}=Le,w=Symbol(`GENERATOR`),T=Symbol(`STYLER`),E=Symbol(`IS_EMPTY`),He=[`ansi`,`ansi`,`ansi256`,`ansi16m`],D=Object.create(null),Ue=(e,t={})=>{if(t.level&&!(Number.isInteger(t.level)&&t.level>=0&&t.level<=3))throw Error("The `level` option should be an integer from 0 to 3");let n=Be?Be.level:0;e.level=t.level===void 0?n:t.level},We=e=>{let t=(...e)=>e.join(` `);return Ue(t,e),Object.setPrototypeOf(t,O.prototype),t};function O(e){return We(e)}Object.setPrototypeOf(O.prototype,Function.prototype);for(let[e,t]of Object.entries(b))D[e]={get(){let n=A(this,qe(t.open,t.close,this[T]),this[E]);return Object.defineProperty(this,e,{value:n}),n}};D.visible={get(){let e=A(this,this[T],!0);return Object.defineProperty(this,`visible`,{value:e}),e}};const k=(e,t,n,...r)=>e===`rgb`?t===`ansi16m`?b[n].ansi16m(...r):t===`ansi256`?b[n].ansi256(b.rgbToAnsi256(...r)):b[n].ansi(b.rgbToAnsi(...r)):e===`hex`?k(`rgb`,t,n,...b.hexToRgb(...r)):b[n][e](...r),Ge=[`rgb`,`hex`,`ansi256`];for(let e of Ge){D[e]={get(){let{level:t}=this;return function(...n){let r=qe(k(e,He[t],`color`,...n),b.color.close,this[T]);return A(this,r,this[E])}}};let t=`bg`+e[0].toUpperCase()+e.slice(1);D[t]={get(){let{level:t}=this;return function(...n){let r=qe(k(e,He[t],`bgColor`,...n),b.bgColor.close,this[T]);return A(this,r,this[E])}}}}const Ke=Object.defineProperties(()=>{},{...D,level:{enumerable:!0,get(){return this[w].level},set(e){this[w].level=e}}}),qe=(e,t,n)=>{let r,i;return n===void 0?(r=e,i=t):(r=n.openAll+e,i=t+n.closeAll),{open:e,close:t,openAll:r,closeAll:i,parent:n}},A=(e,t,n)=>{let r=(...e)=>Je(r,e.length===1?``+e[0]:e.join(` `));return Object.setPrototypeOf(r,Ke),r[w]=e,r[T]=t,r[E]=n,r},Je=(e,t)=>{if(e.level<=0||!t)return e[E]?``:t;let n=e[T];if(n===void 0)return t;let{openAll:r,closeAll:i}=n;if(t.includes(`\x1B`))for(;n!==void 0;)t=Re(t,n.close,n.open),n=n.parent;let a=t.indexOf(`
5
- `);return a!==-1&&(t=ze(t,i,r,a)),r+t+i};Object.defineProperties(O.prototype,D);const Ye=O();O({level:Ve?Ve.level:0});var j=Ye,M=class{emitter;constructor(){this.emitter=r()}on(e,t){_(e).forEach(e=>{this.emitter.on(e,t)})}off(e,t){_(e).forEach(e=>{this.emitter.off(e,t)})}emit(e,t){_(e).forEach(e=>{this.emitter.emit(e,t)})}removeAllListeners(){this.emitter.all.clear()}},Xe=class{listeners;constructor(){this.listeners=new Map}on(e,t){_(e).forEach(e=>{let n=this.listeners.get(e)||new Set;n.add(t),this.listeners.set(e,n)})}off(e,t){_(e).forEach(e=>{let n=this.listeners.get(e);n&&n.delete(t)})}async emit(e,...t){let n=_(e).flatMap(e=>{let t=this.listeners.get(e)||new Set,n=this.listeners.get(`*`)||new Set;return[...Array.from(t),...Array.from(n)]});if(n.length===0)return[];let r=await Promise.all(n.map(async n=>{try{let e=n(...t);return e instanceof Promise?await e:e}catch(t){console.error(`Error in event listener for ${String(e)}:`,t);return}}));return r}removeAllListeners(){this.listeners.clear()}};function N(e,...t){let n=class extends e{static _instance;static getInstance(){return this._instance||(this._instance=new e(...t)),this._instance}static clearInstance(){this._instance=void 0}};return n}var Ze=class extends M{destroy(){this.removeAllListeners()}fatal(e,t,n){this.emit(`fatal`,{code:t,message:e,data:n,timestamp:Date.now()})}error(e,t,n){this.emit(`error`,{code:t,message:e,data:n,timestamp:Date.now()})}warn(e,t,n){this.emit(`warning`,{code:t,message:e,data:n,timestamp:Date.now()})}};const P=N(Ze);var Qe=class{data;_schema;_defaultValue;_path;constructor(e){let{schema:t,default:n,path:r}=e;this._schema=t,this._defaultValue=n,this._path=r}set(e){let t=this._schema[`~standard`].validate(e);if(t instanceof Promise)throw Error(`StructuredConfigFile does not support async validation`);if(t.issues){this.reportInvalidConfigFile(t.issues);return}this.data=this.onBeforeSave(e),this.save(e)}get(){return this.data?this.data:this.load()}getKey(e){let t=this.get();return t[e]}save(e){let t=this.onBeforeSave(e);try{d(this.getFilePath()),i.writeFileSync(this.getFilePath(),JSON.stringify(t,void 0,2))}catch{return}return this.data=t}load(){if(!this.fileExists(this.getFilePath())||!this.canReadWriteFile(this.getFilePath())){this.save(this._defaultValue);let e=this.onAfterLoad(this._defaultValue);return this.data=e,e}try{let e=i.readFileSync(this.getFilePath(),`utf8`),t=this.onAfterLoad(this.parseStoredData(e));return this.data=t,t}catch{return this.data=this._defaultValue}}onBeforeSave(e){return e}onAfterLoad(e){return e}getFilePath(){return this._path}parseStoredData(e){try{let t=n(`string.json.parse`).to(`object`),r=t(e);if(r instanceof n.errors)return this._defaultValue;let i=this._schema[`~standard`].validate(r);if(i instanceof Promise)throw Error(`StructuredConfigFile does not support async validation`);return i.issues?this.migrate(r,this._defaultValue):this.migrate(i.value,this._defaultValue)}catch{return this._defaultValue}}canReadWriteFile(e){try{return i.accessSync(e,i.constants.R_OK|i.constants.W_OK),!0}catch{return!1}}fileExists(e){try{return i.accessSync(e,i.constants.F_OK),!0}catch{return!1}}migrate(e,t){let n={...e};for(let r in t){if(!Object.prototype.hasOwnProperty.call(t,r))continue;r in e?e[r]!==null&&t[r]!==null&&typeof e[r]==`object`&&typeof t[r]==`object`&&!Array.isArray(e[r])&&!Array.isArray(t[r])?n[r]=this.migrate(e[r],t[r]):Array.isArray(t[r])&&(n[r]=e[r]):n[r]=t[r]}return n}reportInvalidConfigFile(e){P.getInstance().error(`Invalid config file`,`INVALID_CONFIG_FILE`,{issues:e.map(e=>e.message),filePath:this._path,data:this.data})}},$e=class e extends M{stream;logPath;baseFileName;currentDate;rotationCheckInterval;isRotating=!1;constructor(e,t){super(),this.logPath=e,this.baseFileName=t.replace(`.log`,``),this.currentDate=this.getDateString(new Date),this.ensureLogDirectory(),this.ensureLogFile(),this.stream=this.createStream(),this.rotationCheckInterval=this.startRotationCheck(),this.cleanupOldLogs()}static scope(t,n){return new e(t,n)}log(...e){this.write(`log`,...e)}error(...e){this.write(`error`,...e)}warn(...e){this.write(`warn`,...e)}info(...e){this.write(`info`,...e)}debug(...e){this.write(`debug`,...e)}async close(){clearInterval(this.rotationCheckInterval),await new Promise(e=>{this.stream.end(()=>e())})}getCurrentFileName(){return this.getFileName(this.currentDate)}static getMessageElements(e,...t){let n=new Date,r=n.toISOString().replace(`T`,` `).replace(/\.\d+Z$/,``)+`.${n.getMilliseconds().toString().padStart(3,`0`)}`,i=t.map(e=>typeof e==`object`?JSON.stringify(e,void 0,2):String(e)).join(` `);return{timestamp:r,level:e,message:i}}getFileName(e){return`${this.baseFileName}-${e}.log`}ensureLogDirectory(){try{s(this.logPath,{recursive:!0})}catch(e){throw console.error(`Failed to create log directory ${this.logPath}:`,e),e}}ensureLogFile(){let e=f(this.logPath,this.getFileName(this.currentDate));if(!o(e))try{u(e,``,`utf8`)}catch(t){throw console.error(`Failed to create log file ${e}:`,t),t}}getDateString(e){return e.toISOString().split(`T`)[0]}createStream(){let e=f(this.logPath,this.getFileName(this.currentDate));return a(e,{flags:`a`,encoding:`utf8`})}async rotateLogs(){if(this.isRotating)return;this.isRotating=!0;let e=this.getDateString(new Date);e!==this.currentDate&&await new Promise(t=>{this.stream.end(()=>{this.currentDate=e,this.stream=this.createStream(),this.cleanupOldLogs(),t()})}),this.isRotating=!1}startRotationCheck(){return setInterval(()=>this.rotateLogs(),6e4)}cleanupOldLogs(){let e=c(this.logPath),t=new Date;t.setDate(t.getDate()-7);let n=e.filter(e=>e.startsWith(this.baseFileName)&&e.endsWith(`.log`)).filter(e=>{let n=e.replace(`${this.baseFileName}-`,``).replace(`.log`,``),r=new Date(n);return r<t});n.forEach(e=>{try{l(f(this.logPath,e))}catch(t){console.error(`Failed to delete old log file ${e}:`,t)}})}write(t,...n){let{timestamp:r,message:i}=e.getMessageElements(t,...n),a=`[${r}] [${t}] ${i}\n`;this.stream.write(a,e=>{e?this.emit(`error`,e):this.emit(`write`,a)})}};const F=()=>p.join(process.env.APPDATA??``,`overlayed`),et=()=>p.join(F(),`logs`),tt=e=>p.join(F(),`apps`,e),nt=e=>p.join(tt(e),`logs`),rt=()=>p.join(F(),`meta.json`);var it=class{fileLogger;path;appId;messageQueue=new we;fileName;_debug=!1;silent=!1;constructor(e){this.fileName=e}init(e,t=!1,n=!1){this.appId=e,this._debug=t,this.silent=n,this.path=nt(e),this.fileLogger=new $e(this.path,this.fileName),this.messageQueue.flush().forEach(e=>{this.fileLogger?.[e.type](...e.args)})}scope(e){if(!this.appId||!this.path)throw Error(`Logger not initialized`);let t=`[${e}]`;return{scope:e=>this.scope(e),error:(...e)=>this.error(t,...e),warn:(...e)=>this.warn(t,...e),info:(...e)=>this.info(t,...e),log:(...e)=>this.log(t,...e),debug:(...e)=>this.debug(t,...e)}}error(...e){this.handle(`error`,...e)}warn(...e){this.handle(`warn`,...e)}info(...e){this.handle(`log`,...e)}debug(...e){this._debug&&this.handle(`debug`,...e)}log(...e){this.handle(`log`,...e)}handle(e,...t){this.logToConsole(e,...t),this.fileLogger?this.fileLogger[e](...t):this.messageQueue.add({type:e,args:t})}logToConsole(e,...t){let n={error:j.red,warn:j.yellow,debug:j.blue,log:j.white};if(this.silent&&!this._debug)return;let{timestamp:r,message:i}=$e.getMessageElements(e,...t),a=console[e],o=n[e];a(`${j.gray(r)} ${o(i)}`)}};const I=N(it,`overlayed.log`);var at=class extends ie{blob;chunkSizeMb;maxConcurrent;shouldStop=!1;constructor(e,t){super(),this.blob=e,this.chunkSizeMb=t.chunkSizeMb,this.maxConcurrent=t.maxConcurrent??3}get totalChunks(){return Math.ceil(this.blob.size/(this.chunkSizeMb*1024*1024))}async chunk(e){let t=this.chunkSizeMb*1024*1024,n=this.totalChunks;if(n===0)return;let r=5,i=new Map,a=new Set,o=new Set,s=[];for(let e=0;e<n;e++)s.push(e);let c=async n=>{let c=n*t,l=Math.min(c+t,this.blob.size),u=this.blob.slice(c,l);try{await e(u,n),o.add(n),this.emit(`chunkComplete`,n),a.delete(n)}catch(e){let t=i.get(n)||0;t<r?(i.set(n,t+1),await new Promise(e=>setTimeout(e,(t+1)*1e3)),s.push(n)):(o.add(n),this.emit(`error`,e),this.shouldStop=!0,a.delete(n))}},l=[],u=async()=>{for(;(s.length>0||a.size>0)&&!this.shouldStop;){if(s.length===0){await new Promise(e=>setTimeout(e,10));continue}let e=s.shift();o.has(e)||a.has(e)||(a.add(e),await c(e))}};for(let e=0;e<this.maxConcurrent;e++)l.push(u());await Promise.all(l)}};function ot(e,t){let{recursive:n}=st(t);return se(e)?n?ct(e).map(t=>[e,t]):ue(e).map(t=>[e,t]):[]}function st(e){return{recursive:e?.recursive??!0}}function ct(e){return ue(e,{withFileTypes:!0}).flatMap(t=>{let n=p.join(e,t.name);return t.isDirectory()?ct(n):[n]})}function lt(e){return e}const ut=e(import.meta.url),{PipeEventServer:dt,PipeEventClient:ft,PipeEventBase:pt,ProcessMonitor:mt,Process:ht,InjectionMethod:gt,AccessLevel:_t,HardwareInterface:vt}=ut(`@overlayed/app/dist/native-interface/build/overlayed_native_interface_x64.node`);var yt=class extends M{server=null;_hasConnection=!1;pipeId;get hasConnection(){return this._hasConnection}constructor(e){super(),this.pipeId=e,this.init()}destroy(){this.server&&(this._hasConnection=!1,this.server?.removeAllListeners(),this.server=null)}init(){this.server=new dt(this.pipeId,{clientCount:1,access:1}),this.server.on(`event`,e=>{try{let t=JSON.parse(e);this.emit(`data`,[t])}catch(e){this.emit(`error`,e)}}),this.server.on(`connected`,()=>{this._hasConnection=!0}),this.server.on(`disconnected`,()=>{this._hasConnection=!1})}};const L=N(yt,`stats-cc`);var bt=class{logger;initialized=!1;constructor(e){this.logger=I.getInstance().scope(e)}init(){this.logger.log(`Initializing`),this.initialized=!0}destroy(){this.logger.log(`Destroying`),this.initialized=!1}},R=class extends M{logger;initialized=!1;constructor(e){super(),this.logger=I.getInstance().scope(e)}init(){this.logger.log(`Initializing`),this.initialized=!0}destroy(){this.logger.log(`Destroying`),this.initialized=!1,this.removeAllListeners()}},xt=class extends Xe{logger;initialized=!1;constructor(e){super(),this.logger=I.getInstance().scope(e)}init(){this.logger.log(`Initializing`),this.initialized=!0}destroy(){this.logger.log(`Destroying`),this.initialized=!1,this.removeAllListeners()}};const z=fe.create({baseURL:`https://updater.stats.cc`,headers:{Accept:`application/json`,"Accept-Encoding":`gzip, deflate, br`}});let St;function Ct(e){St=e}z.interceptors.request.use(e=>{let t=St?.();return t?(e.headers??={},e.headers.Authorization=t,e):e});const B=fe.create({baseURL:`https://api.overlayed.gg`,headers:{Accept:`application/json`,"Accept-Encoding":`gzip, deflate, br`}});let wt,Tt;B.interceptors.request.use(e=>{let t=wt?.(),n=Tt?.();return e.headers??={},t&&(e.headers.Authorization=t),n&&(e.headers[`X-Api-Key`]=n),e});function Et(e,t){if(t<=0)throw Error(`Chunk size must be greater than 0`);if(e.length===0)return[];let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}function Dt(e){return e}function V(e){return e?t=>(e(t),t):Dt}V();const Ot=V();function kt(e){return B.get(`/v1/public/applications/${e}`)}V();function At(e,t){return z.get(`/v1/native/${Mt(e)}/version.txt`,{params:{channel:t},responseType:`text`})}function jt(e,t){return z.get(`/v1/native/${Mt(e)}/files`,{params:{channel:t},responseType:`arraybuffer`})}function Mt(e){return e===`01JXPFK6YQ3N00N2Y9JHFNG55D`||e===`01JZEBPGHT5M4Y6SGY4P7Q9EZT`?`siege-game-module`:e}function Nt(){return B.get(`/v1/public/raven/config`)}V();function Pt(e,t){return B.get(`/v1/public/raven/games/${e}/builds/${t}`)}function Ft(e,t){return B.post(`/v1/public/raven/games/${e}/builds/upload`,null,{params:t})}function It(e,t){let n=new FormData;return n.append(`file`,t.chunk),B.patch(`/v1/public/raven/games/${e}/builds/upload`,n,{params:t})}const Lt=250;function Rt(e){let t=Date.now(),n=e.messages.map(e=>zt(t,e)),r=Et(n,Lt),i=Promise.all(r.map(async t=>B.post(`/v1/public/cortex/events`,{...e,messages:t})));return i.catch(e=>{let t=e?.response?.data||e?.message||e;console.error(`Failed to submit cortex events`,t)}),i}function zt(e,t){let n=e-t.created_at.getTime(),r=Math.max(0,Math.floor(n/1e3));return{properties:t.properties,type:t.type,seconds_offset:r}}function Bt(e){return e instanceof Error&&(e.name===`XiorError`||e.name===`XiorTimeoutError`)}function Vt(e){return!!(e&&`kind`in e.data&&`message`in e.data)}let Ht;function Ut(e){Ht=e}var Wt=class extends R{UPDATE_CHECK_INTERVAL_MS=1e3*60*5;targetDir;updateInterval;constructor(){super(`NativeModuleManager`),this.targetDir=p.join(F(),`resources`),this.logger.log(`Target directory`,this.targetDir)}async initWithDlls(e){super.init(),await h.mkdir(this.targetDir,{recursive:!0}),await this.checkForUpdates(e),clearInterval(this.updateInterval),this.updateInterval=setInterval(()=>this.checkForUpdates(e),this.UPDATE_CHECK_INTERVAL_MS)}destroy(){this.updateInterval&&(clearInterval(this.updateInterval),this.updateInterval=void 0),super.destroy()}async getCurrentVersion(e){try{let t=p.join(this.targetDir,e,`version.txt`);return this.logger.log(`Version Path`,t),await h.readFile(t,`utf-8`)}catch{return null}}getTargetPath(e){return p.join(this.targetDir,e)}getTargetVersionPath(e,t){return p.join(this.getTargetPath(e),t)}async checkForUpdates(e){let t=global.OVERLAYED.APP_BUILD_CHANNEL;if(this.logger.log(`Checking for updates`),!t){this.logger.error(`Invalid VITE_BUILD_CHANNEL`);return}await Ht?.();for(let n of e)try{let{data:e}=await At(n,t),r=await this.getCurrentVersion(n);this.logger.log(`${n} > Update Check. current: ${r}, latest: ${e}`);let i=e!==r;this.logger.log(`${n} > Update found: ${r} -> ${e}`),await this.downloadAndExtractDll(n,e,t,i),this.logger.log(`${n} > Downloaded and extracted`),i&&(this.logger.log(`${n} > Cleaning up versions older than ${e}`),await this.cleanupOldVersions(n,e)),this.emit(`dllUpdated`,{identifier:n,version:e})}catch(e){this.logger.error(`${n} > Error checking/updating`,e)}}async downloadAndExtractDll(e,t,n,r){let{data:i}=await jt(e,n),a=this.getTargetPath(e),o=this.getTargetVersionPath(e,t);await h.mkdir(o,{recursive:!0});let s=new g;await s.loadAsync(i);let c=Object.keys(s.files).map(async t=>{let n=s.files[t];if(n&&!n.dir){let i=p.join(o,t);if(!r)try{await h.access(i,h.constants.F_OK);return}catch{this.logger.warn(`${e} > File missing, re-downloading: ${i}`)}let a=await n.async(`nodebuffer`);await h.writeFile(i,a)}});await Promise.all(c);let l=p.join(a,`version.txt`);this.logger.log(`Saving version file`,l),await h.writeFile(l,t)}async cleanupOldVersions(e,t){let n=p.join(this.targetDir,e),r=await h.readdir(n,{withFileTypes:!0});for(let e of r)e.isDirectory()&&e.name!==t&&await h.rm(p.join(n,e.name),{recursive:!0,force:!0})}};const H=N(Wt);var Gt=class extends R{REFETCH_INTERVAL=1e3*60*5;FAILED_REFETCH_INTERVAL=1e3*30;_ravenConfig;_executableToGameMap=new Map;_executablesArray=[];_refetchIntervalHandler=null;_failedRefetchTimeoutHandler=null;constructor(){super(`RavenManager`)}init(){super.init(),this.fetchRavenConfig(),this._refetchIntervalHandler=setInterval(()=>{this._failedRefetchTimeoutHandler&&(clearTimeout(this._failedRefetchTimeoutHandler),this._failedRefetchTimeoutHandler=null),this.fetchRavenConfig()},this.REFETCH_INTERVAL)}getExecutableData(e){return this._executableToGameMap.get(e.toLowerCase())??null}get executables(){return this._executablesArray}get executablesMap(){return this._executableToGameMap}destroy(){this._refetchIntervalHandler&&clearInterval(this._refetchIntervalHandler),this._failedRefetchTimeoutHandler&&clearTimeout(this._failedRefetchTimeoutHandler),H.getInstance().destroy(),super.destroy()}async fetchRavenConfig(){try{let e=await Nt(),t={games:e.data.games};this._ravenConfig=t,this.resetState();let n=new Set;for(let e of this._ravenConfig.games){for(let t of e.executables){let n=t.toLowerCase();this._executableToGameMap.set(n,e),this._executablesArray.push(n)}e.modules.forEach(e=>n.add(e))}await H.getInstance().initWithDlls(Array.from(n)),this.logger.log(`Raven updated`,this._ravenConfig),this.emit(`executablesUpdated`,{executables:this.executables,map:this._executableToGameMap})}catch(e){this.logger.error(`Failed to fetch Raven config`,e),this._failedRefetchTimeoutHandler=setTimeout(()=>this.fetchRavenConfig(),this.FAILED_REFETCH_INTERVAL)}}resetState(){this._executableToGameMap.clear(),this._executablesArray=[]}};const U=N(Gt),Kt=e(import.meta.url),{PipeEventServer:qt,PipeEventClient:Jt,PipeEventBase:Yt,ProcessMonitor:Xt,Process:W,InjectionMethod:Zt,AccessLevel:Qt,HardwareInterface:$t}=Kt(`@overlayed/app/dist/native-interface/build/overlayed_native_interface_x64.node`);var en=class extends R{_processMonitor;_processes=new Map;boundOnRavenManagerExecutablesUpdated=this.onRavenManagerExecutablesUpdated.bind(this);constructor(){super(`ProcessManager`),this._processMonitor=new Xt}get hasAnyActiveProcesses(){return this.activeProcesses.length>0}get activeProcesses(){return Array.from(this._processes.values()).flat().filter(e=>!e.destroyedAt)}init(){super.init(),U.getInstance().on(`executablesUpdated`,this.boundOnRavenManagerExecutablesUpdated),this._processMonitor.on(`create`,e=>{this.logger.log(`Process created`,e),this.addProcess(e),this.logger.log(`Active Process Count: ${this._processes.size}`),this.emit(`create`,{process:e})}),this._processMonitor.on(`destroy`,e=>{this.logger.log(`Process destroyed`,e),this.deleteProcess(e),this.logger.log(`Active Process Count: ${this._processes.size}`),this.emit(`destroy`,{process:e})})}destroy(){U.getInstance().off(`executablesUpdated`,this.boundOnRavenManagerExecutablesUpdated),this._processes.clear(),this._processMonitor.removeAllListeners(),super.destroy()}isProcessRunning(e){let t=this._processes.get(e);return t?.some(e=>!e.destroyedAt)??!1}onRavenManagerExecutablesUpdated(e){e.executables.forEach(e=>{this.logger.log(`Monitoring process`,e),this._processMonitor.registerProcess(e)})}addProcess(e){if(!e.name)return;let t=this._processes.get(e.name);if(!t){this._processes.set(e.name,[e]);return}this._processes.set(e.name,t.concat(e))}deleteProcess(e){if(!e.name)return;let t=this._processes.get(e.name),n=t?.filter(t=>t.id!==e.id)??[];n.length===0?this._processes.delete(e.name):this._processes.set(e.name,n)}};const G=N(en),tn=e(import.meta.url),{RenderInterface:nn,renderHookPath:rn}=tn(`@overlayed/app/dist/render-interface/build/overlayed_render_interface_x64.node`);var an=class{_instance;_resolution;boundOnResolutionChanged=this.onResolutionChanged.bind(this);constructor(e){this._instance=e,this._resolution={width:0,height:0},this._instance.on(`resolution`,this.boundOnResolutionChanged)}destroy(){this._instance.off(`resolution`,this.boundOnResolutionChanged)}get instance(){return this._instance}get resolution(){return this._resolution}onResolutionChanged(e,t){this._resolution={width:e,height:t}}},on=class{interfaces={};constructor(){}createInterface(e){return this.interfaces[e]||(this.interfaces[e]=new an(new nn(e,{access:1}))),this.interfaces[e]}getInterface(e){return this.interfaces[e]?this.interfaces[e]:this.createInterface(e)}};const K=N(on);var sn=class{options;eventQueue;meta=null;constructor(e){this.options=this.resolveOptions(e),this.eventQueue=new we,this.setupFlushInterval()}track(e,t){this.eventQueue.add({type:e,properties:t,created_at:new Date})}flush(){let e=Array.from(this.eventQueue.flush()),t=e.concat({type:`ping`,properties:{},created_at:new Date});if(!this.meta)throw Error(`Tried to flush Cortex events before meta was set`);try{Rt({...this.meta,messages:t})}catch{}return t}setupFlushInterval(){setInterval(()=>{this.flush()},this.options.batchIntervalSeconds*1e3)}resolveOptions(e){return{batchIntervalSeconds:e?.batchIntervalSeconds??15}}};const q=N(sn),cn=e(import.meta.url),ln=cn.resolve(`@overlayed/app/dist/render-interface/build/overlayed_render_hook_x64.dll`);var un=class extends xt{boundOnProcessCreate=this.onProcessCreate.bind(this);boundOnProcessDestroy=this.onProcessDestroy.bind(this);subscribedGames=new Set;_activeReadyRavenGames=new Set;get isInGame(){return this._activeReadyRavenGames.size>0}constructor(){super(`GameLaunchManager`)}setSubscribedGames(e){this.subscribedGames=new Set(e)}init(){super.init(),K.getInstance().createInterface(`OGG_SIEGE`),G.getInstance().on(`create`,this.boundOnProcessCreate),G.getInstance().on(`destroy`,this.boundOnProcessDestroy)}destroy(){G.getInstance().off(`create`,this.boundOnProcessCreate),G.getInstance().off(`destroy`,this.boundOnProcessDestroy),super.destroy()}async onProcessCreate({process:e}){let t=this.getRavenGame(e);if(!t)return;if(this.subscribedGames.size===0){this.logger.warn(`No subscribed games, skipping`);return}if(q.getInstance().track(`game_launch`,{game:t.identifier}),!this.subscribedGames.has(t.identifier)&&!this.subscribedGames.has(`*`))return;let n=new AbortController;if(await this.emit(`gameLaunch`,{game:t.identifier,reject:()=>n.abort()}),n.signal.aborted)return;if(this.logger.log(`Game Launched`,t),this.logger.log(`Process is elevated: `,e.isElevated),this.logger.log(`Current process is elevated: `,W.currentProcess.isElevated),e.isElevated&&!W.currentProcess.isElevated){P.getInstance().fatal(`Game is elevated but the App is not`,`ELEVATION_MISMATCH`,{appElevated:!!W.currentProcess.isElevated,gameElevated:!!e.isElevated}),this.logger.log(`Game elevated but App is not`,{appElevated:W.currentProcess.isElevated,gameElevated:e.isElevated});return}let r=this.copyDll(ln);if(r)try{await e.injectDll(r),this.logger.log(`Render Interface Injection Successful`,r)}catch(e){this.logger.error(`Render Interface Injection Failed`,e),this.logger.error(`Render Interface Injection Failed`,{renderInterfacePath:r})}let i=t?.modules.map(async t=>{let n=await H.getInstance().getCurrentVersion(t);if(!n)return this.logger.error(`No version found for DLL`,{identifier:t}),Promise.resolve();let r=H.getInstance().getTargetVersionPath(t,n);this.logger.log(`DLL Path`,r);let i=await this.getDllFiles(r);return this.logger.log(`DLL Files`,i),Promise.all(i.map(async t=>{let n=p.basename(t),i=p.join(r,n);if(!i)return Promise.resolve();this.logger.log(`Injecting: `,i);try{return e.injectDll(i).then(()=>{this.logger.log(`Injection Successful`,i)}).catch(e=>{this.logger.error(`Injection Failed [1]`,{targetPath:i},e)})}catch(e){return this.logger.error(`Injection Failed [2]`,{targetPath:i},e),Promise.reject(e)}}))});await Promise.allSettled(i),this._activeReadyRavenGames.add(t.identifier),this.logger.debug(`Active ready raven games`,Array.from(this._activeReadyRavenGames).join(`, `)),this.emit(`gameReadyInternal`,{ravenGame:t,process:e}),this.emit(`gameReady`,{game:t.identifier}),q.getInstance().track(`game_ready`,{game:t.identifier})}copyDll(e){let t=p.basename(e),n=ee(e),r=p.join(F(),`resources`),i=p.join(r,t);this.logger.info(`Copying`,n,`to`,i);try{se(r)||ce(r,{recursive:!0});let e=le(n);de(i,e),ae(n,i)}catch(e){return e.code===`EBUSY`?i:(this.logger.error(`Failed to copy`,e),this.logger.error(`Failed to copy`,{originalPath:n,targetPath:i}),!1)}return i}async getDllFiles(e){try{let t=await h.readdir(e);return t.filter(e=>e.endsWith(`.dll`)).map(t=>p.join(e,t))}catch(t){return this.logger.error(`Failed to read DLL directory`,t),this.logger.error(`Failed to read DLL directory`,{dllPath:e}),[]}}onProcessDestroy({process:e}){let t=this.getRavenGame(e);t&&(this._activeReadyRavenGames.delete(t.identifier),this.logger.debug(`Active ready raven games`,Array.from(this._activeReadyRavenGames).join(`, `)),this.emit(`gameCloseInternal`,{ravenGame:t,process:e}),this.emit(`gameClose`,{game:t.identifier}),q.getInstance().track(`game_close`,{game:t.identifier}))}getRavenGame(e){if(!e.name)return;let t=U.getInstance().getExecutableData(e.name);if(!t){this.logger.error(`No raven game found for process`,{process:e});return}return t}};const J=N(un);var dn=class extends bt{boundOnGameLaunch=this.onGameLaunch.bind(this);constructor(){super(`GameBuildManager`)}init(){super.init(),J.getInstance().on(`gameReadyInternal`,this.boundOnGameLaunch)}destroy(){J.getInstance().off(`gameReadyInternal`,this.boundOnGameLaunch),super.destroy()}async onGameLaunch(...e){let[{ravenGame:t,process:n}]=e;if(!n.path||!n.name){this.logger.error(`Process path or name not found, could not check for build hash`,void 0,n);return}let r=le(n.path),i=pe(`sha256`).update(r).digest(`hex`);this.logger.log(`Process Path`,n.path),this.logger.log(`Process Name`,n.name),this.logger.log(`Build Hash`,i);let a=!1;try{let e=await Pt(t.identifier,i);a=e.data.upload}catch(e){this.logger.error(`Error checking game build hash`,e);return}if(!a){this.logger.log(`Build hash already exists, skipping upload`);return}let o=new g;o.file(n.name,r);let s=await o.generateAsync({type:`blob`});try{this.logger.log(`Uploading build (size: `,s.size,` bytes)`);let e=new at(s,{chunkSizeMb:25,maxConcurrent:1}),n=await Ft(t.identifier,{build_hash:i,chunk_count:e.totalChunks,file_size_bytes:s.size});await e.chunk(async(e,r)=>{this.logger.log(`Uploading chunk`,r),await It(t.identifier,{chunk:e,build_hash:i,chunk_index:r,upload_token:n.data.upload_token})}),this.logger.log(`Build uploaded successfully`)}catch(e){Bt(e)?Vt(e.response)?this.logger.error(`Error uploading build hash, api error`,e):this.logger.error(`Error uploading build hash, request error`,e):this.logger.error(`Error uploading build hash, unknown error`,e)}}};const fn=N(dn);function pn(e=[]){return p.normalize(p.join(tt(global.OVERLAYED.APPLICATION_ID),...e))}const mn=n({game:`string`,type:`string`,creation_time:`number`}),hn=new Qe({path:rt(),schema:n({userId:`string | undefined`}),default:{userId:void 0}});function gn(){let e=hn.get().userId;if(e)return e;let t=_n();return hn.set({userId:t}),t}function _n(){try{return $t.generateUniqueIdentifier()}catch{return crypto.randomUUID()}}function Y(e,t){return`${e}:${t}`}function vn(e,t,n){return e.reduce((e,r)=>{let i=r.key;return e[i]={on(e,n){let r=Y(i,e),a=t.get(r)??new Set;a.add(n),t.set(r,a)},onAny(e){let n=Y(i,`*`),r=t.get(n)??new Set;r.add(e),t.set(n,r)},off(e,n){let r=Y(i,e),a=t.get(r);a&&(a.delete(n),a.size===0&&t.delete(r))},offAny(e){let n=Y(i,`*`),r=t.get(n);r&&(r.delete(e),r.size===0&&t.delete(n))},readyForGameEvents:()=>{n.emit(`flushEvents`,i)}},e},{})}function yn(){let e=P.getInstance(),t=J.getInstance();return{on:(n,r)=>{switch(n){case`fatal`:e.on(`fatal`,r);break;case`error`:e.on(`error`,r);break;case`warning`:e.on(`warning`,r);break;case`gameLaunch`:t.on(`gameLaunch`,r);break;case`gameClose`:t.on(`gameClose`,r);break;case`gameReady`:t.on(`gameReady`,r);break;default:throw Error(`Event type not implemented ${n}`,{cause:[n,r]})}},off:(n,r)=>{switch(n){case`fatal`:e.off(`fatal`,r);break;case`error`:e.off(`error`,r);break;case`warning`:e.off(`warning`,r);break;case`gameLaunch`:t.off(`gameLaunch`,r);break;case`gameClose`:t.off(`gameClose`,r);break;case`gameReady`:t.off(`gameReady`,r);break;default:throw Error(`Event type not implemented ${n}`,{cause:[n,r]})}}}}var X=function(e){return e[e.LeftButton=1]=`LeftButton`,e[e.RightButton=2]=`RightButton`,e[e.Cancel=3]=`Cancel`,e[e.MiddleButton=4]=`MiddleButton`,e[e.ExtraButton1=5]=`ExtraButton1`,e[e.ExtraButton2=6]=`ExtraButton2`,e[e.Back=8]=`Back`,e[e.Tab=9]=`Tab`,e[e.Clear=12]=`Clear`,e[e.Return=13]=`Return`,e[e.Shift=16]=`Shift`,e[e.Control=17]=`Control`,e[e.Menu=18]=`Menu`,e[e.Pause=19]=`Pause`,e[e.CapsLock=20]=`CapsLock`,e[e.Kana=21]=`Kana`,e[e.Hangeul=21]=`Hangeul`,e[e.Hangul=21]=`Hangul`,e[e.Junja=23]=`Junja`,e[e.Final=24]=`Final`,e[e.Hanja=25]=`Hanja`,e[e.Kanji=25]=`Kanji`,e[e.Escape=27]=`Escape`,e[e.Convert=28]=`Convert`,e[e.NonConvert=29]=`NonConvert`,e[e.Accept=30]=`Accept`,e[e.ModeChange=31]=`ModeChange`,e[e.Space=32]=`Space`,e[e.Prior=33]=`Prior`,e[e.Next=34]=`Next`,e[e.End=35]=`End`,e[e.Home=36]=`Home`,e[e.Left=37]=`Left`,e[e.Up=38]=`Up`,e[e.Right=39]=`Right`,e[e.Down=40]=`Down`,e[e.Select=41]=`Select`,e[e.Print=42]=`Print`,e[e.Execute=43]=`Execute`,e[e.Snapshot=44]=`Snapshot`,e[e.Insert=45]=`Insert`,e[e.Delete=46]=`Delete`,e[e.Help=47]=`Help`,e[e.N0=48]=`N0`,e[e.N1=49]=`N1`,e[e.N2=50]=`N2`,e[e.N3=51]=`N3`,e[e.N4=52]=`N4`,e[e.N5=53]=`N5`,e[e.N6=54]=`N6`,e[e.N7=55]=`N7`,e[e.N8=56]=`N8`,e[e.N9=57]=`N9`,e[e.A=65]=`A`,e[e.B=66]=`B`,e[e.C=67]=`C`,e[e.D=68]=`D`,e[e.E=69]=`E`,e[e.F=70]=`F`,e[e.G=71]=`G`,e[e.H=72]=`H`,e[e.I=73]=`I`,e[e.J=74]=`J`,e[e.K=75]=`K`,e[e.L=76]=`L`,e[e.M=77]=`M`,e[e.N=78]=`N`,e[e.O=79]=`O`,e[e.P=80]=`P`,e[e.Q=81]=`Q`,e[e.R=82]=`R`,e[e.S=83]=`S`,e[e.T=84]=`T`,e[e.U=85]=`U`,e[e.V=86]=`V`,e[e.W=87]=`W`,e[e.X=88]=`X`,e[e.Y=89]=`Y`,e[e.Z=90]=`Z`,e[e.LeftWindows=91]=`LeftWindows`,e[e.RightWindows=92]=`RightWindows`,e[e.Application=93]=`Application`,e[e.Sleep=95]=`Sleep`,e[e.Numpad0=96]=`Numpad0`,e[e.Numpad1=97]=`Numpad1`,e[e.Numpad2=98]=`Numpad2`,e[e.Numpad3=99]=`Numpad3`,e[e.Numpad4=100]=`Numpad4`,e[e.Numpad5=101]=`Numpad5`,e[e.Numpad6=102]=`Numpad6`,e[e.Numpad7=103]=`Numpad7`,e[e.Numpad8=104]=`Numpad8`,e[e.Numpad9=105]=`Numpad9`,e[e.Multiply=106]=`Multiply`,e[e.Add=107]=`Add`,e[e.Separator=108]=`Separator`,e[e.Subtract=109]=`Subtract`,e[e.Decimal=110]=`Decimal`,e[e.Divide=111]=`Divide`,e[e.F1=112]=`F1`,e[e.F2=113]=`F2`,e[e.F3=114]=`F3`,e[e.F4=115]=`F4`,e[e.F5=116]=`F5`,e[e.F6=117]=`F6`,e[e.F7=118]=`F7`,e[e.F8=119]=`F8`,e[e.F9=120]=`F9`,e[e.F10=121]=`F10`,e[e.F11=122]=`F11`,e[e.F12=123]=`F12`,e[e.F13=124]=`F13`,e[e.F14=125]=`F14`,e[e.F15=126]=`F15`,e[e.F16=127]=`F16`,e[e.F17=128]=`F17`,e[e.F18=129]=`F18`,e[e.F19=130]=`F19`,e[e.F20=131]=`F20`,e[e.F21=132]=`F21`,e[e.F22=133]=`F22`,e[e.F23=134]=`F23`,e[e.F24=135]=`F24`,e[e.NumLock=144]=`NumLock`,e[e.ScrollLock=145]=`ScrollLock`,e[e.NEC_Equal=146]=`NEC_Equal`,e[e.Fujitsu_Jisho=146]=`Fujitsu_Jisho`,e[e.Fujitsu_Masshou=147]=`Fujitsu_Masshou`,e[e.Fujitsu_Touroku=148]=`Fujitsu_Touroku`,e[e.Fujitsu_Loya=149]=`Fujitsu_Loya`,e[e.Fujitsu_Roya=150]=`Fujitsu_Roya`,e[e.LeftShift=160]=`LeftShift`,e[e.RightShift=161]=`RightShift`,e[e.LeftControl=162]=`LeftControl`,e[e.RightControl=163]=`RightControl`,e[e.LeftMenu=164]=`LeftMenu`,e[e.RightMenu=165]=`RightMenu`,e[e.BrowserBack=166]=`BrowserBack`,e[e.BrowserForward=167]=`BrowserForward`,e[e.BrowserRefresh=168]=`BrowserRefresh`,e[e.BrowserStop=169]=`BrowserStop`,e[e.BrowserSearch=170]=`BrowserSearch`,e[e.BrowserFavorites=171]=`BrowserFavorites`,e[e.BrowserHome=172]=`BrowserHome`,e[e.VolumeMute=173]=`VolumeMute`,e[e.VolumeDown=174]=`VolumeDown`,e[e.VolumeUp=175]=`VolumeUp`,e[e.MediaNextTrack=176]=`MediaNextTrack`,e[e.MediaPrevTrack=177]=`MediaPrevTrack`,e[e.MediaStop=178]=`MediaStop`,e[e.MediaPlayPause=179]=`MediaPlayPause`,e[e.LaunchMail=180]=`LaunchMail`,e[e.LaunchMediaSelect=181]=`LaunchMediaSelect`,e[e.LaunchApplication1=182]=`LaunchApplication1`,e[e.LaunchApplication2=183]=`LaunchApplication2`,e[e.OEM1=186]=`OEM1`,e[e.OEMPlus=187]=`OEMPlus`,e[e.OEMComma=188]=`OEMComma`,e[e.OEMMinus=189]=`OEMMinus`,e[e.OEMPeriod=190]=`OEMPeriod`,e[e.OEM2=191]=`OEM2`,e[e.OEM3=192]=`OEM3`,e[e.OEM4=219]=`OEM4`,e[e.OEM5=220]=`OEM5`,e[e.OEM6=221]=`OEM6`,e[e.OEM7=222]=`OEM7`,e[e.OEM8=223]=`OEM8`,e[e.OEMAX=225]=`OEMAX`,e[e.OEM102=226]=`OEM102`,e[e.ICOHelp=227]=`ICOHelp`,e[e.ICO00=228]=`ICO00`,e[e.ProcessKey=229]=`ProcessKey`,e[e.ICOClear=230]=`ICOClear`,e[e.Packet=231]=`Packet`,e[e.OEMReset=233]=`OEMReset`,e[e.OEMJump=234]=`OEMJump`,e[e.OEMPA1=235]=`OEMPA1`,e[e.OEMPA2=236]=`OEMPA2`,e[e.OEMPA3=237]=`OEMPA3`,e[e.OEMWSCtrl=238]=`OEMWSCtrl`,e[e.OEMCUSel=239]=`OEMCUSel`,e[e.OEMATTN=240]=`OEMATTN`,e[e.OEMFinish=241]=`OEMFinish`,e[e.OEMCopy=242]=`OEMCopy`,e[e.OEMAuto=243]=`OEMAuto`,e[e.OEMENLW=244]=`OEMENLW`,e[e.OEMBackTab=245]=`OEMBackTab`,e[e.ATTN=246]=`ATTN`,e[e.CRSel=247]=`CRSel`,e[e.EXSel=248]=`EXSel`,e[e.EREOF=249]=`EREOF`,e[e.Play=250]=`Play`,e[e.Zoom=251]=`Zoom`,e[e.Noname=252]=`Noname`,e[e.PA1=253]=`PA1`,e[e.OEMClear=254]=`OEMClear`,e}(X||{});const bn=new Map([[X.LeftButton,`LeftButton`],[X.RightButton,`RightButton`],[X.Cancel,`Cancel`],[X.MiddleButton,`MiddleButton`],[X.ExtraButton1,`ExtraButton1`],[X.ExtraButton2,`ExtraButton2`],[X.Back,`Backspace`],[X.Tab,`Tab`],[X.Clear,`Clear`],[X.Return,`Enter`],[X.Shift,`ShiftLeft`],[X.Control,`ControlLeft`],[X.Menu,`AltLeft`],[X.Pause,`Pause`],[X.CapsLock,`CapsLock`],[X.Kana,`KanaMode`],[X.Junja,`JunjaMode`],[X.Final,`Finalize`],[X.Hanja,`HanjaMode`],[X.Escape,`Escape`],[X.Convert,`Convert`],[X.NonConvert,`NonConvert`],[X.Accept,`Accept`],[X.ModeChange,`ModeChange`],[X.Space,`Space`],[X.Prior,`PageUp`],[X.Next,`PageDown`],[X.End,`End`],[X.Home,`Home`],[X.Left,`ArrowLeft`],[X.Up,`ArrowUp`],[X.Right,`ArrowRight`],[X.Down,`ArrowDown`],[X.Select,`Select`],[X.Print,`PrintScreen`],[X.Execute,`Execute`],[X.Snapshot,`Snapshot`],[X.Insert,`Insert`],[X.Delete,`Delete`],[X.Help,`Help`],[X.N0,`Digit0`],[X.N1,`Digit1`],[X.N2,`Digit2`],[X.N3,`Digit3`],[X.N4,`Digit4`],[X.N5,`Digit5`],[X.N6,`Digit6`],[X.N7,`Digit7`],[X.N8,`Digit8`],[X.N9,`Digit9`],[X.A,`KeyA`],[X.B,`KeyB`],[X.C,`KeyC`],[X.D,`KeyD`],[X.E,`KeyE`],[X.F,`KeyF`],[X.G,`KeyG`],[X.H,`KeyH`],[X.I,`KeyI`],[X.J,`KeyJ`],[X.K,`KeyK`],[X.L,`KeyL`],[X.M,`KeyM`],[X.N,`KeyN`],[X.O,`KeyO`],[X.P,`KeyP`],[X.Q,`KeyQ`],[X.R,`KeyR`],[X.S,`KeyS`],[X.T,`KeyT`],[X.U,`KeyU`],[X.V,`KeyV`],[X.W,`KeyW`],[X.X,`KeyX`],[X.Y,`KeyY`],[X.Z,`KeyZ`],[X.LeftWindows,`MetaLeft`],[X.RightWindows,`MetaRight`],[X.Application,`ContextMenu`],[X.Sleep,`Sleep`],[X.Numpad0,`Numpad0`],[X.Numpad1,`Numpad1`],[X.Numpad2,`Numpad2`],[X.Numpad3,`Numpad3`],[X.Numpad4,`Numpad4`],[X.Numpad5,`Numpad5`],[X.Numpad6,`Numpad6`],[X.Numpad7,`Numpad7`],[X.Numpad8,`Numpad8`],[X.Numpad9,`Numpad9`],[X.Multiply,`NumpadMultiply`],[X.Add,`NumpadAdd`],[X.Separator,`NumpadSeparator`],[X.Subtract,`NumpadSubtract`],[X.Decimal,`NumpadDecimal`],[X.Divide,`NumpadDivide`],[X.F1,`F1`],[X.F2,`F2`],[X.F3,`F3`],[X.F4,`F4`],[X.F5,`F5`],[X.F6,`F6`],[X.F7,`F7`],[X.F8,`F8`],[X.F9,`F9`],[X.F10,`F10`],[X.F11,`F11`],[X.F12,`F12`],[X.F13,`F13`],[X.F14,`F14`],[X.F15,`F15`],[X.F16,`F16`],[X.F17,`F17`],[X.F18,`F18`],[X.F19,`F19`],[X.F20,`F20`],[X.F21,`F21`],[X.F22,`F22`],[X.F23,`F23`],[X.F24,`F24`],[X.NumLock,`NumLock`],[X.ScrollLock,`ScrollLock`],[X.NEC_Equal,`NEC_Equal`],[X.Fujitsu_Masshou,`Fujitsu_Masshou`],[X.Fujitsu_Touroku,`Fujitsu_Touroku`],[X.Fujitsu_Loya,`Fujitsu_Loya`],[X.Fujitsu_Roya,`Fujitsu_Roya`],[X.LeftShift,`ShiftLeft`],[X.RightShift,`ShiftRight`],[X.LeftControl,`ControlLeft`],[X.RightControl,`ControlRight`],[X.LeftMenu,`AltLeft`],[X.RightMenu,`AltRight`],[X.BrowserBack,`BrowserBack`],[X.BrowserForward,`BrowserForward`],[X.BrowserRefresh,`BrowserRefresh`],[X.BrowserStop,`BrowserStop`],[X.BrowserSearch,`BrowserSearch`],[X.BrowserFavorites,`BrowserFavorites`],[X.BrowserHome,`BrowserHome`],[X.VolumeMute,`VolumeMute`],[X.VolumeDown,`VolumeDown`],[X.VolumeUp,`VolumeUp`],[X.MediaNextTrack,`MediaTrackNext`],[X.MediaPrevTrack,`MediaTrackPrevious`],[X.MediaStop,`MediaStop`],[X.MediaPlayPause,`MediaPlayPause`],[X.LaunchMail,`LaunchMail`],[X.LaunchMediaSelect,`LaunchMediaSelect`],[X.LaunchApplication1,`LaunchApplication1`],[X.LaunchApplication2,`LaunchApplication2`],[X.OEM1,`OEM_1`],[X.OEMPlus,`Equal`],[X.OEMComma,`Comma`],[X.OEMMinus,`Minus`],[X.OEMPeriod,`Period`],[X.OEM2,`Slash`],[X.OEM3,`Backquote`],[X.OEM4,`BracketLeft`],[X.OEM5,`Backslash`],[X.OEM6,`BracketRight`],[X.OEM7,`Quote`],[X.OEM8,`IntlRo`],[X.OEMAX,`OEM_AX`],[X.OEM102,`IntlBackslash`],[X.ICOHelp,`ICO_HELP`],[X.ICO00,`ICO_00`],[X.ProcessKey,`Process`],[X.ICOClear,`ICO_CLEAR`],[X.Packet,`Packet`],[X.OEMReset,`OEM_Reset`],[X.OEMJump,`OEM_Jump`],[X.OEMPA1,`OEM_PA1`],[X.OEMPA2,`OEM_PA2`],[X.OEMPA3,`OEM_PA3`],[X.OEMWSCtrl,`OEM_WS_Ctrl`],[X.OEMCUSel,`OEM_CU_Sel`],[X.OEMATTN,`OEM_ATTN`],[X.OEMFinish,`OEM_Finish`],[X.OEMCopy,`OEM_Copy`],[X.OEMAuto,`OEM_Auto`],[X.OEMENLW,`OEM_ENLW`],[X.OEMBackTab,`BackTab`],[X.ATTN,`ATTN`],[X.CRSel,`CRSel`],[X.EXSel,`EXSel`],[X.EREOF,`EREOF`],[X.Play,`MediaPlay`],[X.Zoom,`Zoom`],[X.Noname,`Noname`],[X.PA1,`PA1`],[X.OEMClear,`OEM_Clear`]]),xn=new Map(bn.entries().map(([e,t])=>[t,e])),Sn=n({"[string]":{keys:`string[]`,mode:n(`'toggle' | 'hold'`).pipe(e=>e??`toggle`)}});var Cn=class extends R{preferencesKeybindToCallbacks=new Map;pressedKeys=new Set;activeKeybinds=new Set;triggeredToggleKeybinds=new Set;boundHandleKeyboardFocus=this.handleKeyboardFocus.bind(this);boundHandleKeyDown=this.handleKeyDown.bind(this);boundHandleKeyUp=this.handleKeyUp.bind(this);keybindsFile;keybindListeningPaused=!1;constructor(e){super(`KeybindManager`),this.keybindsFile=new Qe({path:pn([`keybinds.json`]),schema:Sn,default:e})}init(){super.init();let e=K.getInstance().getInterface(`OGG_SIEGE`);e.instance.on(`keyboardFocus`,this.boundHandleKeyboardFocus),e.instance.on(`keyDown`,this.boundHandleKeyDown),e.instance.on(`keyUp`,this.boundHandleKeyUp)}async onKeybindToggled(e,t){let n=this.preferencesKeybindToCallbacks.get(e)||{};n.toggle=t,this.preferencesKeybindToCallbacks.set(e,n)}async onKeybindDown(e,t){let n=this.preferencesKeybindToCallbacks.get(e)||{};n.down=t,this.preferencesKeybindToCallbacks.set(e,n)}async onKeybindUp(e,t){let n=this.preferencesKeybindToCallbacks.get(e)||{};n.up=t,this.preferencesKeybindToCallbacks.set(e,n)}async updateKeybind(e,t){this.keybindsFile.set({[e]:t})}async updateKeybinds(e){let t=Object.fromEntries(Object.entries(e).filter(([e,t])=>t!==void 0));this.keybindsFile.set({...this.keybindsFile.get(),...t})}getConfig(){return this.keybindsFile.get()}destroy(){let e=K.getInstance().getInterface(`OGG_SIEGE`);e.instance.off(`keyboardFocus`,this.boundHandleKeyboardFocus),e.instance.off(`keyDown`,this.boundHandleKeyDown),e.instance.off(`keyUp`,this.boundHandleKeyUp),super.destroy()}handleKeyDown(e){if(this.keybindListeningPaused)return;let t=bn.get(e.key);if(!t){this.logger.error(`Unknown key down`,e);return}this.pressedKeys.add(t),this.checkKeybindings()}handleKeyboardFocus(){this.pressedKeys.clear(),this.activeKeybinds.clear(),this.triggeredToggleKeybinds.clear()}async handleKeyUp(e){if(this.keybindListeningPaused)return;let t=bn.get(e.key);if(!t)return;this.pressedKeys.delete(t);let n=this.keybindsFile.get();for(let[e]of this.preferencesKeybindToCallbacks.entries()){let r=n[e];r.keys.includes(t)&&this.triggeredToggleKeybinds.delete(e)}this.checkKeybindUps()}async checkKeybindUps(){let e=this.keybindsFile.get();for(let[t,n]of this.preferencesKeybindToCallbacks.entries()){if(!n.up)continue;let r=e[t];this.activeKeybinds.has(t)&&r.keys.some(e=>!this.pressedKeys.has(e))&&(this.activeKeybinds.delete(t),n.up(),this.logger.log(`Keybind up triggered`,this.getKeybindToString(r)))}}async checkKeybindings(){let e=this.keybindsFile.get();for(let[t,n]of this.preferencesKeybindToCallbacks.entries()){let r=e[t],i=r.keys.length===this.pressedKeys.size&&r.keys.every(e=>xn.has(e)?this.pressedKeys.has(e):!1);if(i){this.triggerKeybind(r,n,t);return}}for(let[t,n]of this.preferencesKeybindToCallbacks.entries()){let r=e[t],i=r.keys.every(e=>xn.has(e)?this.pressedKeys.has(e):(this.logger.error(`Unknown key`,e,r),!1));i&&this.triggerKeybind(r,n,t)}}triggerKeybind(e,t,n){let r=e.mode;if(r===`toggle`&&t.toggle&&!this.triggeredToggleKeybinds.has(n)){let r=t.toggle();this.triggeredToggleKeybinds.add(n),this.logger.log(r?`Keybind pressed rejected: ${r}`:`Keybind pressed accepted`,this.getKeybindToString(e))}if(r===`hold`&&t.down&&!this.activeKeybinds.has(n)){let r=t.down();r?this.logger.log(`Keybind down rejected: ${r}`,this.getKeybindToString(e)):(this.activeKeybinds.add(n),this.logger.log(`Keybind down accepted`,this.getKeybindToString(e)))}}getKeybindToString(e){return`(${e.keys.join(`+`)}${e.mode?` ${e.mode}`:``})`}};function wn(e){let t=new Cn(e),n={};for(let r in e)n[r]={on:(e,n)=>{switch(e){case`down`:t.onKeybindDown(r,n);break;case`up`:t.onKeybindUp(r,n);break;case`toggle`:t.onKeybindToggled(r,n);break;default:throw Error(`Event type not implemented ${e}`,{cause:[e,n]})}}};let r={...n,getConfig:()=>t.getConfig(),pauseKeybindListening:()=>{t.keybindListeningPaused=!0},resumeKeybindListening:()=>{t.keybindListeningPaused=!1},updateKeybind:(e,n)=>{t.updateKeybind(e,n)},updateKeybinds:e=>{t.updateKeybinds(e)}};return t.init(),me.on(`quit`,()=>{t.destroy()}),r}function Z(){return K.getInstance().getInterface(`OGG_SIEGE`)}function Tn(){let e=J.getInstance(),t=P.getInstance(),n=q.getInstance();n.meta=En(),e.on([`gameReady`,`gameClose`],()=>{n.meta||(n.meta=En()),n.meta.in_game=e.isInGame}),t.on(`fatal`,e=>{n.track(`fatal`,{message:e.message,code:e.code,data:JSON.stringify(e.data)})}),t.on(`error`,e=>{n.track(`error`,{code:e.code,message:e.message,data:JSON.stringify(e.data)})}),t.on(`warning`,e=>{n.track(`warning`,{message:e.message,code:e.code,data:JSON.stringify(e.data)})})}function En(){return{app_id:global.OVERLAYED.APPLICATION_ID,user_id:gn(),app_channel:global.OVERLAYED.APP_BUILD_CHANNEL,app_version:global.OVERLAYED.APP_VERSION,package_version:global.OVERLAYED.PACKAGE_VERSION,frontend_version:global.OVERLAYED.FRONTEND_VERSION,session_id:global.OVERLAYED.sessionId,in_game:!1}}function Dn(){function e(e,t){return e.once(`closed`,()=>{e.isDestroyed()||q.getInstance().track(`window_closed`,{url:e.webContents.getURL(),in_game:t})}),e.on(`unresponsive`,()=>{e.isDestroyed()||q.getInstance().track(`window_unresponsive`,{url:e.webContents.getURL(),in_game:t})}),q.getInstance().track(`window_created`,{url:e.webContents.getURL(),in_game:t}),e}return{createWindow:t=>e(new global.OVERLAYED.electron.BrowserWindow(t),!1),createInGameWindow:t=>e(Z().instance.newWindowInternal(global.OVERLAYED.electron.BrowserWindow,t),!0),on:(e,t)=>Z().instance.on(e,t),off:(e,t)=>Z().instance.off(e,t),once:(e,t)=>Z().instance.once(e,t),addListener:(e,t)=>Z().instance.addListener(e,t),removeListener:(e,t)=>Z().instance.removeListener(e,t),removeAllListeners:()=>Z().instance.removeAllListeners(),prependListener:(e,t)=>Z().instance.prependListener(e,t),prependOnceListener:(e,t)=>Z().instance.prependOnceListener(e,t),getActiveGameInfo:()=>{let e=Z(),t=L.getInstance();return{resolution:e.resolution,isConnected:t.hasConnection}}}}var On=class extends bt{renderInterface;globalCursorOverrideCount=new Set;globalMouseBlockCount=new Set;globalKeyboardBlockCount=new Set;keyInputBlocks={};constructor(e){super(`OverridesManager`),this.renderInterface=K.getInstance().getInterface(e)}scope(e){return{setGlobalCursorOverride:t=>this.setGlobalCursorOverride(e,t),setGlobalMouseBlock:t=>this.setGlobalMouseBlock(e,t),setGlobalKeyboardBlock:t=>this.setGlobalKeyboardBlock(e,t),setKeyInputBlock:(t,n)=>this.setKeyInputBlock(e,t,n)}}setGlobalCursorOverride(e,t){t?this.globalCursorOverrideCount.add(e):this.globalCursorOverrideCount.delete(e),t&&this.globalCursorOverrideCount.size===1?this.renderInterface.instance.setGlobalCursorOverride(!0):!t&&this.globalCursorOverrideCount.size===0&&this.renderInterface.instance.setGlobalCursorOverride(!1)}setGlobalMouseBlock(e,t){t?this.globalMouseBlockCount.add(e):this.globalMouseBlockCount.delete(e),t&&this.globalMouseBlockCount.size===1?this.renderInterface.instance.setGlobalMouseBlock(!0):!t&&this.globalMouseBlockCount.size===0&&this.renderInterface.instance.setGlobalMouseBlock(!1)}setGlobalKeyboardBlock(e,t){t?this.globalKeyboardBlockCount.add(e):this.globalKeyboardBlockCount.delete(e),t&&this.globalKeyboardBlockCount.size===1?this.renderInterface.instance.setGlobalKeyboardBlock(!0):!t&&this.globalKeyboardBlockCount.size===0&&this.renderInterface.instance.setGlobalKeyboardBlock(!1)}setKeyInputBlock(e,t,n){this.keyInputBlocks[t]||(this.keyInputBlocks[t]=new Set),n?this.keyInputBlocks[t].add(e):this.keyInputBlocks[t].delete(e),n&&this.keyInputBlocks[t].size===1?this.renderInterface.instance.setKeyInputBlock(t,!0):!n&&this.keyInputBlocks[t].size===0&&this.renderInterface.instance.setKeyInputBlock(t,!1)}};const kn=N(On,`OGG_SIEGE`);function An(){return{scope:e=>kn.getInstance().scope(e),raw:{setGlobalMouseBlock:e=>Z().instance.setGlobalMouseBlock(e),setGlobalKeyboardBlock:e=>Z().instance.setGlobalKeyboardBlock(e),setGlobalCursorOverride:e=>Z().instance.setGlobalCursorOverride(e),setKeyInputBlock:(e,t)=>Z().instance.setKeyInputBlock(e,t),getGlobalMouseBlock:()=>Z().instance.getGlobalMouseBlock(),getGlobalKeyboardBlock:()=>Z().instance.getGlobalKeyboardBlock(),getGlobalCursorOverride:()=>Z().instance.getGlobalCursorOverride(),getKeyInputBlock:e=>Z().instance.getKeyInputBlock(e)}}}function jn(){return{track:(e,t)=>{let n=q.getInstance();n.track(`custom__${String(e)}`,t)}}}var Mn=xe((exports,t)=>{var n=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),r=n((e,t)=>{var n=new Set([`mouseDown`,`mouseUp`,`pointerDown`,`pointerUp`]),r=new WeakSet;function i(e,t,{allowHosts:i}={}){let{shell:a}=t;if(r.has(e))return;r.add(e);let o=e.webContents;function s(e){return!!(!c(e)||i?.includes(e.host))}function c(e){return new URL(o.getURL()).origin!==e.origin}let l=0;function u(){l=Date.now()}function d(){let e=Date.now()-l,t=e<150;return t||console.warn(`was not recently active`,e),t}if(process.platform===`win32`){let t={KEYDOWN:256,LBUTTONUP:514,MBUTTONUP:520,RBUTTONUP:517,XBUTTONUP:524,TOUCH:576};for(let n of Object.values(t))e.hookWindowMessage(n,u)}o.on(`input-event`,(e,t)=>{n.has(t.type)&&u()}),o.on(`will-navigate`,(e,t)=>{let n=e.url||t;if(console.log(`will-navigate`,n),!n)return;let r=new URL(n);if(!s(r)){if(!d()){console.log(`blocked navigation`,n),e.preventDefault();return}c(r)&&(console.log(`external navigation`,n),e.preventDefault(),a.openExternal(n))}}),o.session.on(`will-download`,(e,t)=>{let n=t.getURL();/^blob:/.test(n)||e.preventDefault()}),o.setWindowOpenHandler(e=>{console.log(`window-open`,e.url);let{url:t}=e,n=new URL(t);if(!s(n))return d()?(c(n)&&a.openExternal(e.url),{action:`deny`}):(console.log(`blocked navigation`,t),{action:`deny`})})}t.exports=i}),i=n((e,t)=>{var n=new Set([`Mozilla`,`AppleWebKit`,`Chrome`,`Safari`,`Gecko`,`Firefox`,`OPR`,`Edg`,`Version`,`Mobile`,`curl`,`PostmanRuntime`]);async function r(e,t,r){let{webContents:i}=e,a=await i.executeJavaScript(`navigator.userAgent`);a=a.match(/[^\/]+\/[^\s]+( \([^\)]+\))?/g).map(e=>e.trim()).filter(e=>{let[t]=e.split(`/`,1);return n.has(t)}).join(` `),i.setUserAgent(a),t.app.userAgentFallback=a}t.exports=r}),a=r(),o=i();function s(e,t,n={}){a(e,t,n.linkHandler),o(e,t,n.userAgent)}t.exports={setupRevUtils:s,setupLinkHandler:a,setUserAgent:o}}),Nn=Ce(Mn(),1);function Pn(){return{registerWindow:e=>{(0,Nn.setupRevUtils)(e,global.OVERLAYED.electron)}}}function Fn(e){let t=nt(global.OVERLAYED.APPLICATION_ID),n=ot(t,{recursive:!0}),r=et(),i=ot(r,{recursive:!0});I.getInstance().info(`Logs path: `,t),I.getInstance().info(`Overlayed logs path: `,r);let a=new g;return[...n,...i].forEach(([e,t])=>{I.getInstance().info(`Zipping: `,t);let n=oe(t),r=m(t);a.file(r,n,{compression:`DEFLATE`})}),Object.entries(e?.additionalFiles??{}).forEach(([e,t])=>{I.getInstance().info(`Zipping extra file: `,e),a.file(e,t,{compression:`DEFLATE`})}),a}async function In(e,t){let n={...e,version:`${global.OVERLAYED.APP_VERSION}@${global.OVERLAYED.APP_BUILD_CHANNEL}`,log_zip:`data:application/zip;base64,${t}`};await fetch(`https://api.stats.cc/v1/overlay/contact`,{method:`POST`,body:JSON.stringify(n),redirect:`follow`,headers:{"Content-Type":`application/json`}})}function Ln(e){let t=new it(`app.log`);return t.init(global.OVERLAYED.APPLICATION_ID,e.debug),{scope:e=>t.scope(e),info:e=>t.info(e),warn:e=>t.warn(e),error:e=>t.error(e),debug:e=>t.debug(e),submitBugReport:async(e,t)=>{q.getInstance().track(`bug_report_submitted`,{version:e.version,category:e.category});let n=Fn(t),r=await n.generateAsync({type:`base64`});await In(e,r)}}}const Rn=1e3;function zn(e,t,r,i,a){let o=L.getInstance();function s(e,t){let n=r.get(t);if(!n)r.set(t,[e]);else{if(n.length>=Rn){P.getInstance().warn(`Event buffer full, removing oldest event`,`EVENT_BUFFER_FULL`,{summary:`Event buffer overflow for module ${t}. Buffer size: ${n.length}, max: ${Rn}`});return}n.push(e)}}function c(r){let i=mn(r);if(i instanceof n.errors){q.getInstance().track(`invalid_game_event`,{}),P.getInstance().warn(`Invalid event`,`INVALID_EVENT`,{summary:i.summary});return}let o=e.modules.find(e=>e.key===i.game);if(!o)return;let c=o.events.event,l=c(r);if(l instanceof n.errors){q.getInstance().track(`invalid_game_event`,{game:i.game,type:i.type}),P.getInstance().warn(`Invalid event`,`INVALID_EVENT`,{summary:l.summary});return}if(!a[o.key]){s(l,o.key);return}if(l.type===`unsupported_game_version`){let{content:e}=l;q.getInstance().track(`unsupported_game_version`,{game:l.game,hash:e?.hash,version:e?.version})}let u=Y(o.key,l.type),d=Y(o.key,`*`),f=t.get(u),p=t.get(d),m=[...Array.from(f??[]),...Array.from(p??[])];m.length!==0&&m.forEach(e=>{e(l)})}return i.on(`flushEvents`,e=>{if(a[e])return;a[e]=!0;let t=r.get(e);t&&(I.getInstance().info(`Flushing ${t.length} events for module ${e}`),t.forEach(e=>c(e)),r.delete(e))}),o.on(`data`,e=>e.forEach(c)),o.on(`error`,e=>{P.getInstance().error(`Pipe server error`,`PIPE_SERVER_ERROR`,{error:e})}),o}let Q=!1,Bn={},$,Vn=new M;function Hn(e){let{init:t=!0,debug:n=!1,silent:r=!0}=e;if(Un(e),I.getInstance().init(e.applicationId,n,r),Q)return $;function i(){if(Q)return;Tn();let t=new Map,n=new Map,r=vn(e.modules,t,Vn),a=yn(),o=wn(e.keybinds),s=Dn(),c=An(),l=Pn(),u=jn(),d=Ln(e);Wn(e),zn(e,t,n,Vn,Bn),Q=!0,$={...r,...a,ads:l,keybinds:o,windows:s,input:c,cortex:u,hasAnyActiveProcesses:()=>G.getInstance().hasAnyActiveProcesses,init:i,log:d,initialized:Q}}return t?(i(),$):new Proxy({init:i},{get:(e,t)=>{if(t!==`init`&&!Q)throw Error(`overlayed was called before initialized: ${t}`);return t===`init`?e[t]:$[t]}})}global.OVERLAYED=new Proxy({},{get:()=>{throw Error(`function overlayed was not called`)}});function Un(e){global.OVERLAYED={APPLICATION_ID:Ot(e.applicationId),APP_BUILD_CHANNEL:e.channel??`alpha`,APP_VERSION:e.version??`0.0.0`,PACKAGE_VERSION:`0.18.2`,FRONTEND_VERSION:`0.0.0`,sessionId:crypto.randomUUID(),electron:e.electron}}function Wn(e){let t=e.universal?[`*`]:e.modules.map(e=>e.key);J.getInstance().setSubscribedGames(t),fn.getInstance().init(),J.getInstance().init(),G.getInstance().init(),U.getInstance().init();async function n(){let e=kt(global.OVERLAYED.APPLICATION_ID).then(e=>e.data),t=gn();I.getInstance().log(`userId`,t);let n={...await e,userId:t};return I.getInstance().log(`appInfo`,n),n}let r;global.OVERLAYED.electron.ipcMain.handle(`getAppInfo`,async()=>(r=r??n(),r)),q.getInstance().track(`start`,{}),me.on(`quit`,()=>{q.getInstance().track(`electron_quit`,{}),Gn()}),process.on(`exit`,()=>{q.getInstance().track(`exit`,{}),Gn()})}async function Gn(){await q.getInstance().flush(),U.getInstance().destroy(),J.getInstance().destroy(),fn.getInstance().destroy(),G.getInstance().destroy(),K.getInstance().getInterface(`OGG_SIEGE`).destroy(),L.getInstance().destroy(),P.getInstance().destroy()}export{lt as defineConfig,Hn as overlayed,Ut as setFetchLatestTokenCallback,Ct as setUpdaterTokenResolver};
5
+ `);return a!==-1&&(t=ze(t,i,r,a)),r+t+i};Object.defineProperties(O.prototype,D);const Ye=O();O({level:Ve?Ve.level:0});var j=Ye,M=class{emitter;constructor(){this.emitter=r()}on(e,t){_(e).forEach(e=>{this.emitter.on(e,t)})}off(e,t){_(e).forEach(e=>{this.emitter.off(e,t)})}emit(e,t){_(e).forEach(e=>{this.emitter.emit(e,t)})}removeAllListeners(){this.emitter.all.clear()}},Xe=class{listeners;constructor(){this.listeners=new Map}on(e,t){_(e).forEach(e=>{let n=this.listeners.get(e)||new Set;n.add(t),this.listeners.set(e,n)})}off(e,t){_(e).forEach(e=>{let n=this.listeners.get(e);n&&n.delete(t)})}async emit(e,...t){let n=_(e).flatMap(e=>{let t=this.listeners.get(e)||new Set,n=this.listeners.get(`*`)||new Set;return[...Array.from(t),...Array.from(n)]});if(n.length===0)return[];let r=await Promise.all(n.map(async n=>{try{let e=n(...t);return e instanceof Promise?await e:e}catch(t){console.error(`Error in event listener for ${String(e)}:`,t);return}}));return r}removeAllListeners(){this.listeners.clear()}};function N(e,...t){let n=class extends e{static _instance;static getInstance(){return this._instance||(this._instance=new e(...t)),this._instance}static clearInstance(){this._instance=void 0}};return n}var Ze=class extends M{destroy(){this.removeAllListeners()}fatal(e,t,n){this.emit(`fatal`,{code:t,message:e,data:n,timestamp:Date.now()})}error(e,t,n){this.emit(`error`,{code:t,message:e,data:n,timestamp:Date.now()})}warn(e,t,n){this.emit(`warning`,{code:t,message:e,data:n,timestamp:Date.now()})}};const P=N(Ze);var Qe=class{data;_schema;_defaultValue;_path;constructor(e){let{schema:t,default:n,path:r}=e;this._schema=t,this._defaultValue=n,this._path=r}set(e){let t=this._schema[`~standard`].validate(e);if(t instanceof Promise)throw Error(`StructuredConfigFile does not support async validation`);if(t.issues){this.reportInvalidConfigFile(t.issues);return}this.data=this.onBeforeSave(e),this.save(e)}get(){return this.data?this.data:this.load()}getKey(e){let t=this.get();return t[e]}save(e){let t=this.onBeforeSave(e);try{d(this.getFilePath()),i.writeFileSync(this.getFilePath(),JSON.stringify(t,void 0,2))}catch{return}return this.data=t}load(){if(!this.fileExists(this.getFilePath())||!this.canReadWriteFile(this.getFilePath())){this.save(this._defaultValue);let e=this.onAfterLoad(this._defaultValue);return this.data=e,e}try{let e=i.readFileSync(this.getFilePath(),`utf8`),t=this.onAfterLoad(this.parseStoredData(e));return this.data=t,t}catch{return this.data=this._defaultValue}}onBeforeSave(e){return e}onAfterLoad(e){return e}getFilePath(){return this._path}parseStoredData(e){try{let t=n(`string.json.parse`).to(`object`),r=t(e);if(r instanceof n.errors)return this._defaultValue;let i=this._schema[`~standard`].validate(r);if(i instanceof Promise)throw Error(`StructuredConfigFile does not support async validation`);return i.issues?this.migrate(r,this._defaultValue):this.migrate(i.value,this._defaultValue)}catch{return this._defaultValue}}canReadWriteFile(e){try{return i.accessSync(e,i.constants.R_OK|i.constants.W_OK),!0}catch{return!1}}fileExists(e){try{return i.accessSync(e,i.constants.F_OK),!0}catch{return!1}}migrate(e,t){let n={...e};for(let r in t){if(!Object.prototype.hasOwnProperty.call(t,r))continue;r in e?e[r]!==null&&t[r]!==null&&typeof e[r]==`object`&&typeof t[r]==`object`&&!Array.isArray(e[r])&&!Array.isArray(t[r])?n[r]=this.migrate(e[r],t[r]):Array.isArray(t[r])&&(n[r]=e[r]):n[r]=t[r]}return n}reportInvalidConfigFile(e){P.getInstance().error(`Invalid config file`,`INVALID_CONFIG_FILE`,{issues:e.map(e=>e.message),filePath:this._path,data:this.data})}},$e=class e extends M{stream;logPath;baseFileName;currentDate;rotationCheckInterval;isRotating=!1;constructor(e,t){super(),this.logPath=e,this.baseFileName=t.replace(`.log`,``),this.currentDate=this.getDateString(new Date),this.ensureLogDirectory(),this.ensureLogFile(),this.stream=this.createStream(),this.rotationCheckInterval=this.startRotationCheck(),this.cleanupOldLogs()}static scope(t,n){return new e(t,n)}log(...e){this.write(`log`,...e)}error(...e){this.write(`error`,...e)}warn(...e){this.write(`warn`,...e)}info(...e){this.write(`info`,...e)}debug(...e){this.write(`debug`,...e)}async close(){clearInterval(this.rotationCheckInterval),await new Promise(e=>{this.stream.end(()=>e())})}getCurrentFileName(){return this.getFileName(this.currentDate)}static getMessageElements(e,...t){let n=new Date,r=n.toISOString().replace(`T`,` `).replace(/\.\d+Z$/,``)+`.${n.getMilliseconds().toString().padStart(3,`0`)}`,i=t.map(e=>typeof e==`object`?JSON.stringify(e,void 0,2):String(e)).join(` `);return{timestamp:r,level:e,message:i}}getFileName(e){return`${this.baseFileName}-${e}.log`}ensureLogDirectory(){try{s(this.logPath,{recursive:!0})}catch(e){throw console.error(`Failed to create log directory ${this.logPath}:`,e),e}}ensureLogFile(){let e=f(this.logPath,this.getFileName(this.currentDate));if(!o(e))try{u(e,``,`utf8`)}catch(t){throw console.error(`Failed to create log file ${e}:`,t),t}}getDateString(e){return e.toISOString().split(`T`)[0]}createStream(){let e=f(this.logPath,this.getFileName(this.currentDate));return a(e,{flags:`a`,encoding:`utf8`})}async rotateLogs(){if(this.isRotating)return;this.isRotating=!0;let e=this.getDateString(new Date);e!==this.currentDate&&await new Promise(t=>{this.stream.end(()=>{this.currentDate=e,this.stream=this.createStream(),this.cleanupOldLogs(),t()})}),this.isRotating=!1}startRotationCheck(){return setInterval(()=>this.rotateLogs(),6e4)}cleanupOldLogs(){let e=c(this.logPath),t=new Date;t.setDate(t.getDate()-7);let n=e.filter(e=>e.startsWith(this.baseFileName)&&e.endsWith(`.log`)).filter(e=>{let n=e.replace(`${this.baseFileName}-`,``).replace(`.log`,``),r=new Date(n);return r<t});n.forEach(e=>{try{l(f(this.logPath,e))}catch(t){console.error(`Failed to delete old log file ${e}:`,t)}})}write(t,...n){let{timestamp:r,message:i}=e.getMessageElements(t,...n),a=`[${r}] [${t}] ${i}\n`;this.stream.write(a,e=>{e?this.emit(`error`,e):this.emit(`write`,a)})}};const F=()=>p.join(process.env.APPDATA??``,`overlayed`),et=()=>p.join(F(),`logs`),tt=e=>p.join(F(),`apps`,e),nt=e=>p.join(tt(e),`logs`),rt=()=>p.join(F(),`meta.json`);var it=class{fileLogger;path;appId;messageQueue=new we;fileName;_debug=!1;silent=!1;constructor(e){this.fileName=e}init(e,t=!1,n=!1){this.appId=e,this._debug=t,this.silent=n,this.path=nt(e),this.fileLogger=new $e(this.path,this.fileName),this.messageQueue.flush().forEach(e=>{this.fileLogger?.[e.type](...e.args)})}scope(e){if(!this.appId||!this.path)throw Error(`Logger not initialized`);let t=`[${e}]`;return{scope:e=>this.scope(e),error:(...e)=>this.error(t,...e),warn:(...e)=>this.warn(t,...e),info:(...e)=>this.info(t,...e),log:(...e)=>this.log(t,...e),debug:(...e)=>this.debug(t,...e)}}error(...e){this.handle(`error`,...e)}warn(...e){this.handle(`warn`,...e)}info(...e){this.handle(`log`,...e)}debug(...e){this._debug&&this.handle(`debug`,...e)}log(...e){this.handle(`log`,...e)}handle(e,...t){this.logToConsole(e,...t),this.fileLogger?this.fileLogger[e](...t):this.messageQueue.add({type:e,args:t})}logToConsole(e,...t){let n={error:j.red,warn:j.yellow,debug:j.blue,log:j.white};if(this.silent&&!this._debug)return;let{timestamp:r,message:i}=$e.getMessageElements(e,...t),a=console[e],o=n[e];a(`${j.gray(r)} ${o(i)}`)}};const I=N(it,`overlayed.log`);var at=class extends ie{blob;chunkSizeMb;maxConcurrent;shouldStop=!1;constructor(e,t){super(),this.blob=e,this.chunkSizeMb=t.chunkSizeMb,this.maxConcurrent=t.maxConcurrent??3}get totalChunks(){return Math.ceil(this.blob.size/(this.chunkSizeMb*1024*1024))}async chunk(e){let t=this.chunkSizeMb*1024*1024,n=this.totalChunks;if(n===0)return;let r=5,i=new Map,a=new Set,o=new Set,s=[];for(let e=0;e<n;e++)s.push(e);let c=async n=>{let c=n*t,l=Math.min(c+t,this.blob.size),u=this.blob.slice(c,l);try{await e(u,n),o.add(n),this.emit(`chunkComplete`,n),a.delete(n)}catch(e){let t=i.get(n)||0;t<r?(i.set(n,t+1),await new Promise(e=>setTimeout(e,(t+1)*1e3)),s.push(n)):(o.add(n),this.emit(`error`,e),this.shouldStop=!0,a.delete(n))}},l=[],u=async()=>{for(;(s.length>0||a.size>0)&&!this.shouldStop;){if(s.length===0){await new Promise(e=>setTimeout(e,10));continue}let e=s.shift();o.has(e)||a.has(e)||(a.add(e),await c(e))}};for(let e=0;e<this.maxConcurrent;e++)l.push(u());await Promise.all(l)}};function ot(e,t){let{recursive:n}=st(t);return se(e)?n?ct(e).map(t=>[e,t]):ue(e).map(t=>[e,t]):[]}function st(e){return{recursive:e?.recursive??!0}}function ct(e){return ue(e,{withFileTypes:!0}).flatMap(t=>{let n=p.join(e,t.name);return t.isDirectory()?ct(n):[n]})}function lt(e){return e}const ut=e(import.meta.url),{PipeEventServer:dt,PipeEventClient:ft,PipeEventBase:pt,ProcessMonitor:mt,Process:ht,InjectionMethod:gt,AccessLevel:_t,HardwareInterface:vt}=ut(`@overlayed/app/dist/native-interface/build/overlayed_native_interface_x64.node`);var yt=class extends M{server=null;_hasConnection=!1;pipeId;get hasConnection(){return this._hasConnection}constructor(e){super(),this.pipeId=e,this.init()}destroy(){this.server&&(this._hasConnection=!1,this.server?.removeAllListeners(),this.server=null)}init(){this.server=new dt(this.pipeId,{clientCount:1,access:1}),this.server.on(`event`,e=>{try{let t=JSON.parse(e);this.emit(`data`,[t])}catch(e){this.emit(`error`,e)}}),this.server.on(`connected`,()=>{this._hasConnection=!0}),this.server.on(`disconnected`,()=>{this._hasConnection=!1})}};const L=N(yt,`stats-cc`);var bt=class{logger;initialized=!1;constructor(e){this.logger=I.getInstance().scope(e)}init(){this.logger.log(`Initializing`),this.initialized=!0}destroy(){this.logger.log(`Destroying`),this.initialized=!1}},R=class extends M{logger;initialized=!1;constructor(e){super(),this.logger=I.getInstance().scope(e)}init(){this.logger.log(`Initializing`),this.initialized=!0}destroy(){this.logger.log(`Destroying`),this.initialized=!1,this.removeAllListeners()}},xt=class extends Xe{logger;initialized=!1;constructor(e){super(),this.logger=I.getInstance().scope(e)}init(){this.logger.log(`Initializing`),this.initialized=!0}destroy(){this.logger.log(`Destroying`),this.initialized=!1,this.removeAllListeners()}};const z=fe.create({baseURL:`https://updater.stats.cc`,headers:{Accept:`application/json`,"Accept-Encoding":`gzip, deflate, br`}});let St;function Ct(e){St=e}z.interceptors.request.use(e=>{let t=St?.();return t?(e.headers??={},e.headers.Authorization=t,e):e});const B=fe.create({baseURL:`https://api.overlayed.gg`,headers:{Accept:`application/json`,"Accept-Encoding":`gzip, deflate, br`}});let wt,Tt;B.interceptors.request.use(e=>{let t=wt?.(),n=Tt?.();return e.headers??={},t&&(e.headers.Authorization=t),n&&(e.headers[`X-Api-Key`]=n),e});function Et(e,t){if(t<=0)throw Error(`Chunk size must be greater than 0`);if(e.length===0)return[];let n=[];for(let r=0;r<e.length;r+=t)n.push(e.slice(r,r+t));return n}function Dt(e){return e}function V(e){return e?t=>(e(t),t):Dt}V();const Ot=V();function kt(e){return B.get(`/v1/public/applications/${e}`)}V();function At(e,t){return z.get(`/v1/native/${Mt(e)}/version.txt`,{params:{channel:t},responseType:`text`})}function jt(e,t){return z.get(`/v1/native/${Mt(e)}/files`,{params:{channel:t},responseType:`arraybuffer`})}function Mt(e){return e===`01JXPFK6YQ3N00N2Y9JHFNG55D`||e===`01JZEBPGHT5M4Y6SGY4P7Q9EZT`?`siege-game-module`:e}function Nt(){return B.get(`/v1/public/raven/config`)}V();function Pt(e,t){return B.get(`/v1/public/raven/games/${e}/builds/${t}`)}function Ft(e,t){return B.post(`/v1/public/raven/games/${e}/builds/upload`,null,{params:t})}function It(e,t){let n=new FormData;return n.append(`file`,t.chunk),B.patch(`/v1/public/raven/games/${e}/builds/upload`,n,{params:t})}const Lt=250;function Rt(e){let t=Date.now(),n=e.messages.map(e=>zt(t,e)),r=Et(n,Lt),i=Promise.all(r.map(async t=>B.post(`/v1/public/cortex/events`,{...e,messages:t})));return i.catch(e=>{let t=e?.response?.data||e?.message||e;console.error(`Failed to submit cortex events`,t)}),i}function zt(e,t){let n=e-t.created_at.getTime(),r=Math.max(0,Math.floor(n/1e3));return{properties:t.properties,type:t.type,seconds_offset:r}}function Bt(e){return e instanceof Error&&(e.name===`XiorError`||e.name===`XiorTimeoutError`)}function Vt(e){return!!(e&&`kind`in e.data&&`message`in e.data)}let Ht;function Ut(e){Ht=e}var Wt=class extends R{UPDATE_CHECK_INTERVAL_MS=1e3*60*5;targetDir;updateInterval;constructor(){super(`NativeModuleManager`),this.targetDir=p.join(F(),`resources`),this.logger.log(`Target directory`,this.targetDir)}async initWithDlls(e){super.init(),await h.mkdir(this.targetDir,{recursive:!0}),await this.checkForUpdates(e),clearInterval(this.updateInterval),this.updateInterval=setInterval(()=>this.checkForUpdates(e),this.UPDATE_CHECK_INTERVAL_MS)}destroy(){this.updateInterval&&(clearInterval(this.updateInterval),this.updateInterval=void 0),super.destroy()}async getCurrentVersion(e){try{let t=p.join(this.targetDir,e,`version.txt`);return this.logger.log(`Version Path`,t),await h.readFile(t,`utf-8`)}catch{return null}}getTargetPath(e){return p.join(this.targetDir,e)}getTargetVersionPath(e,t){return p.join(this.getTargetPath(e),t)}async checkForUpdates(e){let t=global.OVERLAYED.APP_BUILD_CHANNEL;if(this.logger.log(`Checking for updates`),!t){this.logger.error(`Invalid VITE_BUILD_CHANNEL`);return}await Ht?.();for(let n of e)try{let{data:e}=await At(n,t),r=await this.getCurrentVersion(n);this.logger.log(`${n} > Update Check. current: ${r}, latest: ${e}`);let i=e!==r;this.logger.log(`${n} > Update found: ${r} -> ${e}`),await this.downloadAndExtractDll(n,e,t,i),this.logger.log(`${n} > Downloaded and extracted`),i&&(this.logger.log(`${n} > Cleaning up versions older than ${e}`),await this.cleanupOldVersions(n,e)),this.emit(`dllUpdated`,{identifier:n,version:e})}catch(e){this.logger.error(`${n} > Error checking/updating`,e)}}async downloadAndExtractDll(e,t,n,r){let{data:i}=await jt(e,n),a=this.getTargetPath(e),o=this.getTargetVersionPath(e,t);await h.mkdir(o,{recursive:!0});let s=new g;await s.loadAsync(i);let c=Object.keys(s.files).map(async t=>{let n=s.files[t];if(n&&!n.dir){let i=p.join(o,t);if(!r)try{await h.access(i,h.constants.F_OK);return}catch{this.logger.warn(`${e} > File missing, re-downloading: ${i}`)}let a=await n.async(`nodebuffer`);await h.writeFile(i,a)}});await Promise.all(c);let l=p.join(a,`version.txt`);this.logger.log(`Saving version file`,l),await h.writeFile(l,t)}async cleanupOldVersions(e,t){let n=p.join(this.targetDir,e),r=await h.readdir(n,{withFileTypes:!0});for(let e of r)e.isDirectory()&&e.name!==t&&await h.rm(p.join(n,e.name),{recursive:!0,force:!0})}};const H=N(Wt);var Gt=class extends R{REFETCH_INTERVAL=1e3*60*5;FAILED_REFETCH_INTERVAL=1e3*30;_ravenConfig;_executableToGameMap=new Map;_executablesArray=[];_refetchIntervalHandler=null;_failedRefetchTimeoutHandler=null;constructor(){super(`RavenManager`)}init(){super.init(),this.fetchRavenConfig(),this._refetchIntervalHandler=setInterval(()=>{this._failedRefetchTimeoutHandler&&(clearTimeout(this._failedRefetchTimeoutHandler),this._failedRefetchTimeoutHandler=null),this.fetchRavenConfig()},this.REFETCH_INTERVAL)}getExecutableData(e){return this._executableToGameMap.get(e.toLowerCase())??null}get executables(){return this._executablesArray}get executablesMap(){return this._executableToGameMap}destroy(){this._refetchIntervalHandler&&clearInterval(this._refetchIntervalHandler),this._failedRefetchTimeoutHandler&&clearTimeout(this._failedRefetchTimeoutHandler),H.getInstance().destroy(),super.destroy()}async fetchRavenConfig(){try{let e=await Nt(),t={games:e.data.games};this._ravenConfig=t,this.resetState();let n=new Set;for(let e of this._ravenConfig.games){for(let t of e.executables){let n=t.toLowerCase();this._executableToGameMap.set(n,e),this._executablesArray.push(n)}e.modules.forEach(e=>n.add(e))}await H.getInstance().initWithDlls(Array.from(n)),this.logger.log(`Raven updated`,this._ravenConfig),this.emit(`executablesUpdated`,{executables:this.executables,map:this._executableToGameMap})}catch(e){this.logger.error(`Failed to fetch Raven config`,e),this._failedRefetchTimeoutHandler=setTimeout(()=>this.fetchRavenConfig(),this.FAILED_REFETCH_INTERVAL)}}resetState(){this._executableToGameMap.clear(),this._executablesArray=[]}};const U=N(Gt),Kt=e(import.meta.url),{PipeEventServer:qt,PipeEventClient:Jt,PipeEventBase:Yt,ProcessMonitor:Xt,Process:W,InjectionMethod:Zt,AccessLevel:Qt,HardwareInterface:$t}=Kt(`@overlayed/app/dist/native-interface/build/overlayed_native_interface_x64.node`);var en=class extends R{_processMonitor;_processes=new Map;boundOnRavenManagerExecutablesUpdated=this.onRavenManagerExecutablesUpdated.bind(this);constructor(){super(`ProcessManager`),this._processMonitor=new Xt}get hasAnyActiveProcesses(){return this.activeProcesses.length>0}get activeProcesses(){return Array.from(this._processes.values()).flat().filter(e=>!e.destroyedAt)}init(){super.init(),U.getInstance().on(`executablesUpdated`,this.boundOnRavenManagerExecutablesUpdated),this._processMonitor.on(`create`,e=>{this.logger.log(`Process created`,e),this.addProcess(e),this.logger.log(`Active Process Count: ${this._processes.size}`),this.emit(`create`,{process:e})}),this._processMonitor.on(`destroy`,e=>{this.logger.log(`Process destroyed`,e),this.deleteProcess(e),this.logger.log(`Active Process Count: ${this._processes.size}`),this.emit(`destroy`,{process:e})})}destroy(){U.getInstance().off(`executablesUpdated`,this.boundOnRavenManagerExecutablesUpdated),this._processes.clear(),this._processMonitor.removeAllListeners(),super.destroy()}isProcessRunning(e){let t=this._processes.get(e);return t?.some(e=>!e.destroyedAt)??!1}onRavenManagerExecutablesUpdated(e){e.executables.forEach(e=>{this.logger.log(`Monitoring process`,e),this._processMonitor.registerProcess(e)})}addProcess(e){if(!e.name)return;let t=this._processes.get(e.name);if(!t){this._processes.set(e.name,[e]);return}this._processes.set(e.name,t.concat(e))}deleteProcess(e){if(!e.name)return;let t=this._processes.get(e.name),n=t?.filter(t=>t.id!==e.id)??[];n.length===0?this._processes.delete(e.name):this._processes.set(e.name,n)}};const G=N(en),tn=e(import.meta.url),{RenderInterface:nn,renderHookPath:rn}=tn(`@overlayed/app/dist/render-interface/build/overlayed_render_interface_x64.node`);var an=class{_instance;_resolution;boundOnResolutionChanged=this.onResolutionChanged.bind(this);constructor(e){this._instance=e,this._resolution={width:0,height:0},this._instance.on(`resolution`,this.boundOnResolutionChanged)}destroy(){this._instance.off(`resolution`,this.boundOnResolutionChanged)}get instance(){return this._instance}get resolution(){return this._resolution}onResolutionChanged(e,t){this._resolution={width:e,height:t}}},on=class{interfaces={};constructor(){}createInterface(e){return this.interfaces[e]||(this.interfaces[e]=new an(new nn(e,{access:1}))),this.interfaces[e]}getInterface(e){return this.interfaces[e]?this.interfaces[e]:this.createInterface(e)}};const K=N(on);var sn=class{options;eventQueue;meta=null;constructor(e){this.options=this.resolveOptions(e),this.eventQueue=new we,this.setupFlushInterval()}track(e,t){this.eventQueue.add({type:e,properties:t,created_at:new Date})}flush(){let e=Array.from(this.eventQueue.flush()),t=e.concat({type:`ping`,properties:{},created_at:new Date});if(!this.meta)throw Error(`Tried to flush Cortex events before meta was set`);try{Rt({...this.meta,messages:t})}catch{}return t}setupFlushInterval(){setInterval(()=>{this.flush()},this.options.batchIntervalSeconds*1e3)}resolveOptions(e){return{batchIntervalSeconds:e?.batchIntervalSeconds??15}}};const q=N(sn),cn=e(import.meta.url),ln=cn.resolve(`@overlayed/app/dist/render-interface/build/overlayed_render_hook_x64.dll`);var un=class extends xt{boundOnProcessCreate=this.onProcessCreate.bind(this);boundOnProcessDestroy=this.onProcessDestroy.bind(this);subscribedGames=new Set;_activeReadyRavenGames=new Set;get isInGame(){return this._activeReadyRavenGames.size>0}constructor(){super(`GameLaunchManager`)}setSubscribedGames(e){this.subscribedGames=new Set(e)}init(){super.init(),K.getInstance().createInterface(`OGG_SIEGE`),G.getInstance().on(`create`,this.boundOnProcessCreate),G.getInstance().on(`destroy`,this.boundOnProcessDestroy)}destroy(){G.getInstance().off(`create`,this.boundOnProcessCreate),G.getInstance().off(`destroy`,this.boundOnProcessDestroy),super.destroy()}async onProcessCreate({process:e}){let t=this.getRavenGame(e);if(!t)return;if(this.subscribedGames.size===0){this.logger.warn(`No subscribed games, skipping`);return}if(q.getInstance().track(`game_launch`,{game:t.identifier}),!this.subscribedGames.has(t.identifier)&&!this.subscribedGames.has(`*`))return;let n=new AbortController;if(await this.emit(`gameLaunch`,{game:t.identifier,reject:()=>n.abort()}),n.signal.aborted)return;if(this.logger.log(`Game Launched`,t),this.logger.log(`Process is elevated: `,e.isElevated),this.logger.log(`Current process is elevated: `,W.currentProcess.isElevated),e.isElevated&&!W.currentProcess.isElevated){P.getInstance().fatal(`Game is elevated but the App is not`,`ELEVATION_MISMATCH`,{appElevated:!!W.currentProcess.isElevated,gameElevated:!!e.isElevated}),this.logger.log(`Game elevated but App is not`,{appElevated:W.currentProcess.isElevated,gameElevated:e.isElevated});return}let r=this.copyDll(ln);if(r)try{await e.injectDll(r),this.logger.log(`Render Interface Injection Successful`,r)}catch(e){this.logger.error(`Render Interface Injection Failed`,e),this.logger.error(`Render Interface Injection Failed`,{renderInterfacePath:r})}let i=t?.modules.map(async t=>{let n=await H.getInstance().getCurrentVersion(t);if(!n)return this.logger.error(`No version found for DLL`,{identifier:t}),Promise.resolve();let r=H.getInstance().getTargetVersionPath(t,n);this.logger.log(`DLL Path`,r);let i=await this.getDllFiles(r);return this.logger.log(`DLL Files`,i),Promise.all(i.map(async t=>{let n=p.basename(t),i=p.join(r,n);if(!i)return Promise.resolve();this.logger.log(`Injecting: `,i);try{return e.injectDll(i).then(()=>{this.logger.log(`Injection Successful`,i)}).catch(e=>{this.logger.error(`Injection Failed [1]`,{targetPath:i},e)})}catch(e){return this.logger.error(`Injection Failed [2]`,{targetPath:i},e),Promise.reject(e)}}))});await Promise.allSettled(i),this._activeReadyRavenGames.add(t.identifier),this.logger.debug(`Active ready raven games`,Array.from(this._activeReadyRavenGames).join(`, `)),this.emit(`gameReadyInternal`,{ravenGame:t,process:e}),this.emit(`gameReady`,{game:t.identifier}),q.getInstance().track(`game_ready`,{game:t.identifier})}copyDll(e){let t=p.basename(e),n=ee(e),r=p.join(F(),`resources`),i=p.join(r,t);this.logger.info(`Copying`,n,`to`,i);try{se(r)||ce(r,{recursive:!0});let e=le(n);de(i,e),ae(n,i)}catch(e){return e.code===`EBUSY`?i:(this.logger.error(`Failed to copy`,e),this.logger.error(`Failed to copy`,{originalPath:n,targetPath:i}),!1)}return i}async getDllFiles(e){try{let t=await h.readdir(e);return t.filter(e=>e.endsWith(`.dll`)).map(t=>p.join(e,t))}catch(t){return this.logger.error(`Failed to read DLL directory`,t),this.logger.error(`Failed to read DLL directory`,{dllPath:e}),[]}}onProcessDestroy({process:e}){let t=this.getRavenGame(e);t&&(this._activeReadyRavenGames.delete(t.identifier),this.logger.debug(`Active ready raven games`,Array.from(this._activeReadyRavenGames).join(`, `)),this.emit(`gameCloseInternal`,{ravenGame:t,process:e}),this.emit(`gameClose`,{game:t.identifier}),q.getInstance().track(`game_close`,{game:t.identifier}))}getRavenGame(e){if(!e.name)return;let t=U.getInstance().getExecutableData(e.name);if(!t){this.logger.error(`No raven game found for process`,{process:e});return}return t}};const J=N(un);var dn=class extends bt{boundOnGameLaunch=this.onGameLaunch.bind(this);constructor(){super(`GameBuildManager`)}init(){super.init(),J.getInstance().on(`gameReadyInternal`,this.boundOnGameLaunch)}destroy(){J.getInstance().off(`gameReadyInternal`,this.boundOnGameLaunch),super.destroy()}async onGameLaunch(...e){let[{ravenGame:t,process:n}]=e;if(!n.path||!n.name){this.logger.error(`Process path or name not found, could not check for build hash`,void 0,n);return}let r=le(n.path),i=pe(`sha256`).update(r).digest(`hex`);this.logger.log(`Process Path`,n.path),this.logger.log(`Process Name`,n.name),this.logger.log(`Build Hash`,i);let a=!1;try{let e=await Pt(t.identifier,i);a=e.data.upload}catch(e){this.logger.error(`Error checking game build hash`,e);return}if(!a){this.logger.log(`Build hash already exists, skipping upload`);return}let o=new g;o.file(n.name,r);let s=await o.generateAsync({type:`blob`});try{this.logger.log(`Uploading build (size: `,s.size,` bytes)`);let e=new at(s,{chunkSizeMb:25,maxConcurrent:1}),n=await Ft(t.identifier,{build_hash:i,chunk_count:e.totalChunks,file_size_bytes:s.size});await e.chunk(async(e,r)=>{this.logger.log(`Uploading chunk`,r),await It(t.identifier,{chunk:e,build_hash:i,chunk_index:r,upload_token:n.data.upload_token})}),this.logger.log(`Build uploaded successfully`)}catch(e){Bt(e)?Vt(e.response)?this.logger.error(`Error uploading build hash, api error`,e):this.logger.error(`Error uploading build hash, request error`,e):this.logger.error(`Error uploading build hash, unknown error`,e)}}};const fn=N(dn);function pn(e=[]){return p.normalize(p.join(tt(global.OVERLAYED.APPLICATION_ID),...e))}const mn=n({game:`string`,type:`string`,creation_time:`number`}),hn=new Qe({path:rt(),schema:n({userId:`string | undefined`}),default:{userId:void 0}});function gn(){let e=hn.get().userId;if(e)return e;let t=_n();return hn.set({userId:t}),t}function _n(){try{return $t.generateUniqueIdentifier()}catch{return crypto.randomUUID()}}function Y(e,t){return`${e}:${t}`}function vn(e,t,n){return e.reduce((e,r)=>{let i=r.key;return e[i]={on(e,n){let r=Y(i,e),a=t.get(r)??new Set;a.add(n),t.set(r,a)},onAny(e){let n=Y(i,`*`),r=t.get(n)??new Set;r.add(e),t.set(n,r)},off(e,n){let r=Y(i,e),a=t.get(r);a&&(a.delete(n),a.size===0&&t.delete(r))},offAny(e){let n=Y(i,`*`),r=t.get(n);r&&(r.delete(e),r.size===0&&t.delete(n))},readyForGameEvents:()=>{n.emit(`flushEvents`,i)}},e},{})}function yn(){let e=P.getInstance(),t=J.getInstance();return{on:(n,r)=>{switch(n){case`fatal`:e.on(`fatal`,r);break;case`error`:e.on(`error`,r);break;case`warning`:e.on(`warning`,r);break;case`gameLaunch`:t.on(`gameLaunch`,r);break;case`gameClose`:t.on(`gameClose`,r);break;case`gameReady`:t.on(`gameReady`,r);break;default:throw Error(`Event type not implemented ${n}`,{cause:[n,r]})}},off:(n,r)=>{switch(n){case`fatal`:e.off(`fatal`,r);break;case`error`:e.off(`error`,r);break;case`warning`:e.off(`warning`,r);break;case`gameLaunch`:t.off(`gameLaunch`,r);break;case`gameClose`:t.off(`gameClose`,r);break;case`gameReady`:t.off(`gameReady`,r);break;default:throw Error(`Event type not implemented ${n}`,{cause:[n,r]})}}}}var X=function(e){return e[e.LeftButton=1]=`LeftButton`,e[e.RightButton=2]=`RightButton`,e[e.Cancel=3]=`Cancel`,e[e.MiddleButton=4]=`MiddleButton`,e[e.ExtraButton1=5]=`ExtraButton1`,e[e.ExtraButton2=6]=`ExtraButton2`,e[e.Back=8]=`Back`,e[e.Tab=9]=`Tab`,e[e.Clear=12]=`Clear`,e[e.Return=13]=`Return`,e[e.Shift=16]=`Shift`,e[e.Control=17]=`Control`,e[e.Menu=18]=`Menu`,e[e.Pause=19]=`Pause`,e[e.CapsLock=20]=`CapsLock`,e[e.Kana=21]=`Kana`,e[e.Hangeul=21]=`Hangeul`,e[e.Hangul=21]=`Hangul`,e[e.Junja=23]=`Junja`,e[e.Final=24]=`Final`,e[e.Hanja=25]=`Hanja`,e[e.Kanji=25]=`Kanji`,e[e.Escape=27]=`Escape`,e[e.Convert=28]=`Convert`,e[e.NonConvert=29]=`NonConvert`,e[e.Accept=30]=`Accept`,e[e.ModeChange=31]=`ModeChange`,e[e.Space=32]=`Space`,e[e.Prior=33]=`Prior`,e[e.Next=34]=`Next`,e[e.End=35]=`End`,e[e.Home=36]=`Home`,e[e.Left=37]=`Left`,e[e.Up=38]=`Up`,e[e.Right=39]=`Right`,e[e.Down=40]=`Down`,e[e.Select=41]=`Select`,e[e.Print=42]=`Print`,e[e.Execute=43]=`Execute`,e[e.Snapshot=44]=`Snapshot`,e[e.Insert=45]=`Insert`,e[e.Delete=46]=`Delete`,e[e.Help=47]=`Help`,e[e.N0=48]=`N0`,e[e.N1=49]=`N1`,e[e.N2=50]=`N2`,e[e.N3=51]=`N3`,e[e.N4=52]=`N4`,e[e.N5=53]=`N5`,e[e.N6=54]=`N6`,e[e.N7=55]=`N7`,e[e.N8=56]=`N8`,e[e.N9=57]=`N9`,e[e.A=65]=`A`,e[e.B=66]=`B`,e[e.C=67]=`C`,e[e.D=68]=`D`,e[e.E=69]=`E`,e[e.F=70]=`F`,e[e.G=71]=`G`,e[e.H=72]=`H`,e[e.I=73]=`I`,e[e.J=74]=`J`,e[e.K=75]=`K`,e[e.L=76]=`L`,e[e.M=77]=`M`,e[e.N=78]=`N`,e[e.O=79]=`O`,e[e.P=80]=`P`,e[e.Q=81]=`Q`,e[e.R=82]=`R`,e[e.S=83]=`S`,e[e.T=84]=`T`,e[e.U=85]=`U`,e[e.V=86]=`V`,e[e.W=87]=`W`,e[e.X=88]=`X`,e[e.Y=89]=`Y`,e[e.Z=90]=`Z`,e[e.LeftWindows=91]=`LeftWindows`,e[e.RightWindows=92]=`RightWindows`,e[e.Application=93]=`Application`,e[e.Sleep=95]=`Sleep`,e[e.Numpad0=96]=`Numpad0`,e[e.Numpad1=97]=`Numpad1`,e[e.Numpad2=98]=`Numpad2`,e[e.Numpad3=99]=`Numpad3`,e[e.Numpad4=100]=`Numpad4`,e[e.Numpad5=101]=`Numpad5`,e[e.Numpad6=102]=`Numpad6`,e[e.Numpad7=103]=`Numpad7`,e[e.Numpad8=104]=`Numpad8`,e[e.Numpad9=105]=`Numpad9`,e[e.Multiply=106]=`Multiply`,e[e.Add=107]=`Add`,e[e.Separator=108]=`Separator`,e[e.Subtract=109]=`Subtract`,e[e.Decimal=110]=`Decimal`,e[e.Divide=111]=`Divide`,e[e.F1=112]=`F1`,e[e.F2=113]=`F2`,e[e.F3=114]=`F3`,e[e.F4=115]=`F4`,e[e.F5=116]=`F5`,e[e.F6=117]=`F6`,e[e.F7=118]=`F7`,e[e.F8=119]=`F8`,e[e.F9=120]=`F9`,e[e.F10=121]=`F10`,e[e.F11=122]=`F11`,e[e.F12=123]=`F12`,e[e.F13=124]=`F13`,e[e.F14=125]=`F14`,e[e.F15=126]=`F15`,e[e.F16=127]=`F16`,e[e.F17=128]=`F17`,e[e.F18=129]=`F18`,e[e.F19=130]=`F19`,e[e.F20=131]=`F20`,e[e.F21=132]=`F21`,e[e.F22=133]=`F22`,e[e.F23=134]=`F23`,e[e.F24=135]=`F24`,e[e.NumLock=144]=`NumLock`,e[e.ScrollLock=145]=`ScrollLock`,e[e.NEC_Equal=146]=`NEC_Equal`,e[e.Fujitsu_Jisho=146]=`Fujitsu_Jisho`,e[e.Fujitsu_Masshou=147]=`Fujitsu_Masshou`,e[e.Fujitsu_Touroku=148]=`Fujitsu_Touroku`,e[e.Fujitsu_Loya=149]=`Fujitsu_Loya`,e[e.Fujitsu_Roya=150]=`Fujitsu_Roya`,e[e.LeftShift=160]=`LeftShift`,e[e.RightShift=161]=`RightShift`,e[e.LeftControl=162]=`LeftControl`,e[e.RightControl=163]=`RightControl`,e[e.LeftMenu=164]=`LeftMenu`,e[e.RightMenu=165]=`RightMenu`,e[e.BrowserBack=166]=`BrowserBack`,e[e.BrowserForward=167]=`BrowserForward`,e[e.BrowserRefresh=168]=`BrowserRefresh`,e[e.BrowserStop=169]=`BrowserStop`,e[e.BrowserSearch=170]=`BrowserSearch`,e[e.BrowserFavorites=171]=`BrowserFavorites`,e[e.BrowserHome=172]=`BrowserHome`,e[e.VolumeMute=173]=`VolumeMute`,e[e.VolumeDown=174]=`VolumeDown`,e[e.VolumeUp=175]=`VolumeUp`,e[e.MediaNextTrack=176]=`MediaNextTrack`,e[e.MediaPrevTrack=177]=`MediaPrevTrack`,e[e.MediaStop=178]=`MediaStop`,e[e.MediaPlayPause=179]=`MediaPlayPause`,e[e.LaunchMail=180]=`LaunchMail`,e[e.LaunchMediaSelect=181]=`LaunchMediaSelect`,e[e.LaunchApplication1=182]=`LaunchApplication1`,e[e.LaunchApplication2=183]=`LaunchApplication2`,e[e.OEM1=186]=`OEM1`,e[e.OEMPlus=187]=`OEMPlus`,e[e.OEMComma=188]=`OEMComma`,e[e.OEMMinus=189]=`OEMMinus`,e[e.OEMPeriod=190]=`OEMPeriod`,e[e.OEM2=191]=`OEM2`,e[e.OEM3=192]=`OEM3`,e[e.OEM4=219]=`OEM4`,e[e.OEM5=220]=`OEM5`,e[e.OEM6=221]=`OEM6`,e[e.OEM7=222]=`OEM7`,e[e.OEM8=223]=`OEM8`,e[e.OEMAX=225]=`OEMAX`,e[e.OEM102=226]=`OEM102`,e[e.ICOHelp=227]=`ICOHelp`,e[e.ICO00=228]=`ICO00`,e[e.ProcessKey=229]=`ProcessKey`,e[e.ICOClear=230]=`ICOClear`,e[e.Packet=231]=`Packet`,e[e.OEMReset=233]=`OEMReset`,e[e.OEMJump=234]=`OEMJump`,e[e.OEMPA1=235]=`OEMPA1`,e[e.OEMPA2=236]=`OEMPA2`,e[e.OEMPA3=237]=`OEMPA3`,e[e.OEMWSCtrl=238]=`OEMWSCtrl`,e[e.OEMCUSel=239]=`OEMCUSel`,e[e.OEMATTN=240]=`OEMATTN`,e[e.OEMFinish=241]=`OEMFinish`,e[e.OEMCopy=242]=`OEMCopy`,e[e.OEMAuto=243]=`OEMAuto`,e[e.OEMENLW=244]=`OEMENLW`,e[e.OEMBackTab=245]=`OEMBackTab`,e[e.ATTN=246]=`ATTN`,e[e.CRSel=247]=`CRSel`,e[e.EXSel=248]=`EXSel`,e[e.EREOF=249]=`EREOF`,e[e.Play=250]=`Play`,e[e.Zoom=251]=`Zoom`,e[e.Noname=252]=`Noname`,e[e.PA1=253]=`PA1`,e[e.OEMClear=254]=`OEMClear`,e}(X||{});const bn=new Map([[X.LeftButton,`LeftButton`],[X.RightButton,`RightButton`],[X.Cancel,`Cancel`],[X.MiddleButton,`MiddleButton`],[X.ExtraButton1,`ExtraButton1`],[X.ExtraButton2,`ExtraButton2`],[X.Back,`Backspace`],[X.Tab,`Tab`],[X.Clear,`Clear`],[X.Return,`Enter`],[X.Shift,`ShiftLeft`],[X.Control,`ControlLeft`],[X.Menu,`AltLeft`],[X.Pause,`Pause`],[X.CapsLock,`CapsLock`],[X.Kana,`KanaMode`],[X.Junja,`JunjaMode`],[X.Final,`Finalize`],[X.Hanja,`HanjaMode`],[X.Escape,`Escape`],[X.Convert,`Convert`],[X.NonConvert,`NonConvert`],[X.Accept,`Accept`],[X.ModeChange,`ModeChange`],[X.Space,`Space`],[X.Prior,`PageUp`],[X.Next,`PageDown`],[X.End,`End`],[X.Home,`Home`],[X.Left,`ArrowLeft`],[X.Up,`ArrowUp`],[X.Right,`ArrowRight`],[X.Down,`ArrowDown`],[X.Select,`Select`],[X.Print,`PrintScreen`],[X.Execute,`Execute`],[X.Snapshot,`Snapshot`],[X.Insert,`Insert`],[X.Delete,`Delete`],[X.Help,`Help`],[X.N0,`Digit0`],[X.N1,`Digit1`],[X.N2,`Digit2`],[X.N3,`Digit3`],[X.N4,`Digit4`],[X.N5,`Digit5`],[X.N6,`Digit6`],[X.N7,`Digit7`],[X.N8,`Digit8`],[X.N9,`Digit9`],[X.A,`KeyA`],[X.B,`KeyB`],[X.C,`KeyC`],[X.D,`KeyD`],[X.E,`KeyE`],[X.F,`KeyF`],[X.G,`KeyG`],[X.H,`KeyH`],[X.I,`KeyI`],[X.J,`KeyJ`],[X.K,`KeyK`],[X.L,`KeyL`],[X.M,`KeyM`],[X.N,`KeyN`],[X.O,`KeyO`],[X.P,`KeyP`],[X.Q,`KeyQ`],[X.R,`KeyR`],[X.S,`KeyS`],[X.T,`KeyT`],[X.U,`KeyU`],[X.V,`KeyV`],[X.W,`KeyW`],[X.X,`KeyX`],[X.Y,`KeyY`],[X.Z,`KeyZ`],[X.LeftWindows,`MetaLeft`],[X.RightWindows,`MetaRight`],[X.Application,`ContextMenu`],[X.Sleep,`Sleep`],[X.Numpad0,`Numpad0`],[X.Numpad1,`Numpad1`],[X.Numpad2,`Numpad2`],[X.Numpad3,`Numpad3`],[X.Numpad4,`Numpad4`],[X.Numpad5,`Numpad5`],[X.Numpad6,`Numpad6`],[X.Numpad7,`Numpad7`],[X.Numpad8,`Numpad8`],[X.Numpad9,`Numpad9`],[X.Multiply,`NumpadMultiply`],[X.Add,`NumpadAdd`],[X.Separator,`NumpadSeparator`],[X.Subtract,`NumpadSubtract`],[X.Decimal,`NumpadDecimal`],[X.Divide,`NumpadDivide`],[X.F1,`F1`],[X.F2,`F2`],[X.F3,`F3`],[X.F4,`F4`],[X.F5,`F5`],[X.F6,`F6`],[X.F7,`F7`],[X.F8,`F8`],[X.F9,`F9`],[X.F10,`F10`],[X.F11,`F11`],[X.F12,`F12`],[X.F13,`F13`],[X.F14,`F14`],[X.F15,`F15`],[X.F16,`F16`],[X.F17,`F17`],[X.F18,`F18`],[X.F19,`F19`],[X.F20,`F20`],[X.F21,`F21`],[X.F22,`F22`],[X.F23,`F23`],[X.F24,`F24`],[X.NumLock,`NumLock`],[X.ScrollLock,`ScrollLock`],[X.NEC_Equal,`NEC_Equal`],[X.Fujitsu_Masshou,`Fujitsu_Masshou`],[X.Fujitsu_Touroku,`Fujitsu_Touroku`],[X.Fujitsu_Loya,`Fujitsu_Loya`],[X.Fujitsu_Roya,`Fujitsu_Roya`],[X.LeftShift,`ShiftLeft`],[X.RightShift,`ShiftRight`],[X.LeftControl,`ControlLeft`],[X.RightControl,`ControlRight`],[X.LeftMenu,`AltLeft`],[X.RightMenu,`AltRight`],[X.BrowserBack,`BrowserBack`],[X.BrowserForward,`BrowserForward`],[X.BrowserRefresh,`BrowserRefresh`],[X.BrowserStop,`BrowserStop`],[X.BrowserSearch,`BrowserSearch`],[X.BrowserFavorites,`BrowserFavorites`],[X.BrowserHome,`BrowserHome`],[X.VolumeMute,`VolumeMute`],[X.VolumeDown,`VolumeDown`],[X.VolumeUp,`VolumeUp`],[X.MediaNextTrack,`MediaTrackNext`],[X.MediaPrevTrack,`MediaTrackPrevious`],[X.MediaStop,`MediaStop`],[X.MediaPlayPause,`MediaPlayPause`],[X.LaunchMail,`LaunchMail`],[X.LaunchMediaSelect,`LaunchMediaSelect`],[X.LaunchApplication1,`LaunchApplication1`],[X.LaunchApplication2,`LaunchApplication2`],[X.OEM1,`OEM_1`],[X.OEMPlus,`Equal`],[X.OEMComma,`Comma`],[X.OEMMinus,`Minus`],[X.OEMPeriod,`Period`],[X.OEM2,`Slash`],[X.OEM3,`Backquote`],[X.OEM4,`BracketLeft`],[X.OEM5,`Backslash`],[X.OEM6,`BracketRight`],[X.OEM7,`Quote`],[X.OEM8,`IntlRo`],[X.OEMAX,`OEM_AX`],[X.OEM102,`IntlBackslash`],[X.ICOHelp,`ICO_HELP`],[X.ICO00,`ICO_00`],[X.ProcessKey,`Process`],[X.ICOClear,`ICO_CLEAR`],[X.Packet,`Packet`],[X.OEMReset,`OEM_Reset`],[X.OEMJump,`OEM_Jump`],[X.OEMPA1,`OEM_PA1`],[X.OEMPA2,`OEM_PA2`],[X.OEMPA3,`OEM_PA3`],[X.OEMWSCtrl,`OEM_WS_Ctrl`],[X.OEMCUSel,`OEM_CU_Sel`],[X.OEMATTN,`OEM_ATTN`],[X.OEMFinish,`OEM_Finish`],[X.OEMCopy,`OEM_Copy`],[X.OEMAuto,`OEM_Auto`],[X.OEMENLW,`OEM_ENLW`],[X.OEMBackTab,`BackTab`],[X.ATTN,`ATTN`],[X.CRSel,`CRSel`],[X.EXSel,`EXSel`],[X.EREOF,`EREOF`],[X.Play,`MediaPlay`],[X.Zoom,`Zoom`],[X.Noname,`Noname`],[X.PA1,`PA1`],[X.OEMClear,`OEM_Clear`]]),xn=new Map(bn.entries().map(([e,t])=>[t,e])),Sn=n({"[string]":{keys:`string[]`,mode:n(`'toggle' | 'hold'`).pipe(e=>e??`toggle`)}});var Cn=class extends R{preferencesKeybindToCallbacks=new Map;pressedKeys=new Set;activeKeybinds=new Set;triggeredToggleKeybinds=new Set;boundHandleKeyboardFocus=this.handleKeyboardFocus.bind(this);boundHandleKeyDown=this.handleKeyDown.bind(this);boundHandleKeyUp=this.handleKeyUp.bind(this);keybindsFile;keybindListeningPaused=!1;constructor(e){super(`KeybindManager`),this.keybindsFile=new Qe({path:pn([`keybinds.json`]),schema:Sn,default:e})}init(){super.init();let e=K.getInstance().getInterface(`OGG_SIEGE`);e.instance.on(`keyboardFocus`,this.boundHandleKeyboardFocus),e.instance.on(`keyDown`,this.boundHandleKeyDown),e.instance.on(`keyUp`,this.boundHandleKeyUp)}async onKeybindToggled(e,t){let n=this.preferencesKeybindToCallbacks.get(e)||{};n.toggle=t,this.preferencesKeybindToCallbacks.set(e,n)}async onKeybindDown(e,t){let n=this.preferencesKeybindToCallbacks.get(e)||{};n.down=t,this.preferencesKeybindToCallbacks.set(e,n)}async onKeybindUp(e,t){let n=this.preferencesKeybindToCallbacks.get(e)||{};n.up=t,this.preferencesKeybindToCallbacks.set(e,n)}async updateKeybind(e,t){this.keybindsFile.set({[e]:t})}async updateKeybinds(e){let t=Object.fromEntries(Object.entries(e).filter(([e,t])=>t!==void 0));this.keybindsFile.set({...this.keybindsFile.get(),...t})}getConfig(){return this.keybindsFile.get()}destroy(){let e=K.getInstance().getInterface(`OGG_SIEGE`);e.instance.off(`keyboardFocus`,this.boundHandleKeyboardFocus),e.instance.off(`keyDown`,this.boundHandleKeyDown),e.instance.off(`keyUp`,this.boundHandleKeyUp),super.destroy()}handleKeyDown(e){if(this.keybindListeningPaused)return;let t=bn.get(e.key);if(!t){this.logger.error(`Unknown key down`,e);return}this.pressedKeys.add(t),this.checkKeybindings()}handleKeyboardFocus(){this.pressedKeys.clear(),this.activeKeybinds.clear(),this.triggeredToggleKeybinds.clear()}async handleKeyUp(e){if(this.keybindListeningPaused)return;let t=bn.get(e.key);if(!t)return;this.pressedKeys.delete(t);let n=this.keybindsFile.get();for(let[e]of this.preferencesKeybindToCallbacks.entries()){let r=n[e];r.keys.includes(t)&&this.triggeredToggleKeybinds.delete(e)}this.checkKeybindUps()}async checkKeybindUps(){let e=this.keybindsFile.get();for(let[t,n]of this.preferencesKeybindToCallbacks.entries()){if(!n.up)continue;let r=e[t];this.activeKeybinds.has(t)&&r.keys.some(e=>!this.pressedKeys.has(e))&&(this.activeKeybinds.delete(t),n.up(),this.logger.log(`Keybind up triggered`,this.getKeybindToString(r)))}}async checkKeybindings(){let e=this.keybindsFile.get();for(let[t,n]of this.preferencesKeybindToCallbacks.entries()){let r=e[t],i=r.keys.length===this.pressedKeys.size&&r.keys.every(e=>xn.has(e)?this.pressedKeys.has(e):!1);if(i){this.triggerKeybind(r,n,t);return}}for(let[t,n]of this.preferencesKeybindToCallbacks.entries()){let r=e[t],i=r.keys.every(e=>xn.has(e)?this.pressedKeys.has(e):(this.logger.error(`Unknown key`,e,r),!1));i&&this.triggerKeybind(r,n,t)}}triggerKeybind(e,t,n){let r=e.mode;if(r===`toggle`&&t.toggle&&!this.triggeredToggleKeybinds.has(n)){let r=t.toggle();this.triggeredToggleKeybinds.add(n),this.logger.log(r?`Keybind pressed rejected: ${r}`:`Keybind pressed accepted`,this.getKeybindToString(e))}if(r===`hold`&&t.down&&!this.activeKeybinds.has(n)){let r=t.down();r?this.logger.log(`Keybind down rejected: ${r}`,this.getKeybindToString(e)):(this.activeKeybinds.add(n),this.logger.log(`Keybind down accepted`,this.getKeybindToString(e)))}}getKeybindToString(e){return`(${e.keys.join(`+`)}${e.mode?` ${e.mode}`:``})`}};function wn(e){let t=new Cn(e),n={};for(let r in e)n[r]={on:(e,n)=>{switch(e){case`down`:t.onKeybindDown(r,n);break;case`up`:t.onKeybindUp(r,n);break;case`toggle`:t.onKeybindToggled(r,n);break;default:throw Error(`Event type not implemented ${e}`,{cause:[e,n]})}}};let r={...n,getConfig:()=>t.getConfig(),pauseKeybindListening:()=>{t.keybindListeningPaused=!0},resumeKeybindListening:()=>{t.keybindListeningPaused=!1},updateKeybind:(e,n)=>{t.updateKeybind(e,n)},updateKeybinds:e=>{t.updateKeybinds(e)}};return t.init(),me.on(`quit`,()=>{t.destroy()}),r}function Z(){return K.getInstance().getInterface(`OGG_SIEGE`)}function Tn(){let e=J.getInstance(),t=P.getInstance(),n=q.getInstance();n.meta=En(),e.on([`gameReady`,`gameClose`],()=>{n.meta||(n.meta=En()),n.meta.in_game=e.isInGame}),t.on(`fatal`,e=>{n.track(`fatal`,{message:e.message,code:e.code,data:JSON.stringify(e.data)})}),t.on(`error`,e=>{n.track(`error`,{code:e.code,message:e.message,data:JSON.stringify(e.data)})}),t.on(`warning`,e=>{n.track(`warning`,{message:e.message,code:e.code,data:JSON.stringify(e.data)})})}function En(){return{app_id:global.OVERLAYED.APPLICATION_ID,user_id:gn(),app_channel:global.OVERLAYED.APP_BUILD_CHANNEL,app_version:global.OVERLAYED.APP_VERSION,package_version:global.OVERLAYED.PACKAGE_VERSION,frontend_version:global.OVERLAYED.FRONTEND_VERSION,session_id:global.OVERLAYED.sessionId,in_game:!1}}function Dn(){function e(e,t){return e.once(`closed`,()=>{e.isDestroyed()||q.getInstance().track(`window_closed`,{url:e.webContents.getURL(),in_game:t})}),e.on(`unresponsive`,()=>{e.isDestroyed()||q.getInstance().track(`window_unresponsive`,{url:e.webContents.getURL(),in_game:t})}),q.getInstance().track(`window_created`,{url:e.webContents.getURL(),in_game:t}),e}return{createWindow:t=>e(new global.OVERLAYED.electron.BrowserWindow(t),!1),createInGameWindow:t=>e(Z().instance.newWindowInternal(global.OVERLAYED.electron.BrowserWindow,t),!0),on:(e,t)=>Z().instance.on(e,t),off:(e,t)=>Z().instance.off(e,t),once:(e,t)=>Z().instance.once(e,t),addListener:(e,t)=>Z().instance.addListener(e,t),removeListener:(e,t)=>Z().instance.removeListener(e,t),removeAllListeners:()=>Z().instance.removeAllListeners(),prependListener:(e,t)=>Z().instance.prependListener(e,t),prependOnceListener:(e,t)=>Z().instance.prependOnceListener(e,t),getActiveGameInfo:()=>{let e=Z(),t=L.getInstance();return{resolution:e.resolution,isConnected:t.hasConnection}}}}var On=class extends bt{renderInterface;globalCursorOverrideCount=new Set;globalMouseBlockCount=new Set;globalKeyboardBlockCount=new Set;keyInputBlocks={};constructor(e){super(`OverridesManager`),this.renderInterface=K.getInstance().getInterface(e)}scope(e){return{setGlobalCursorOverride:t=>this.setGlobalCursorOverride(e,t),setGlobalMouseBlock:t=>this.setGlobalMouseBlock(e,t),setGlobalKeyboardBlock:t=>this.setGlobalKeyboardBlock(e,t),setKeyInputBlock:(t,n)=>this.setKeyInputBlock(e,t,n)}}setGlobalCursorOverride(e,t){t?this.globalCursorOverrideCount.add(e):this.globalCursorOverrideCount.delete(e),t&&this.globalCursorOverrideCount.size===1?this.renderInterface.instance.setGlobalCursorOverride(!0):!t&&this.globalCursorOverrideCount.size===0&&this.renderInterface.instance.setGlobalCursorOverride(!1)}setGlobalMouseBlock(e,t){t?this.globalMouseBlockCount.add(e):this.globalMouseBlockCount.delete(e),t&&this.globalMouseBlockCount.size===1?this.renderInterface.instance.setGlobalMouseBlock(!0):!t&&this.globalMouseBlockCount.size===0&&this.renderInterface.instance.setGlobalMouseBlock(!1)}setGlobalKeyboardBlock(e,t){t?this.globalKeyboardBlockCount.add(e):this.globalKeyboardBlockCount.delete(e),t&&this.globalKeyboardBlockCount.size===1?this.renderInterface.instance.setGlobalKeyboardBlock(!0):!t&&this.globalKeyboardBlockCount.size===0&&this.renderInterface.instance.setGlobalKeyboardBlock(!1)}setKeyInputBlock(e,t,n){this.keyInputBlocks[t]||(this.keyInputBlocks[t]=new Set),n?this.keyInputBlocks[t].add(e):this.keyInputBlocks[t].delete(e),n&&this.keyInputBlocks[t].size===1?this.renderInterface.instance.setKeyInputBlock(t,!0):!n&&this.keyInputBlocks[t].size===0&&this.renderInterface.instance.setKeyInputBlock(t,!1)}};const kn=N(On,`OGG_SIEGE`);function An(){return{scope:e=>kn.getInstance().scope(e),raw:{setGlobalMouseBlock:e=>Z().instance.setGlobalMouseBlock(e),setGlobalKeyboardBlock:e=>Z().instance.setGlobalKeyboardBlock(e),setGlobalCursorOverride:e=>Z().instance.setGlobalCursorOverride(e),setKeyInputBlock:(e,t)=>Z().instance.setKeyInputBlock(e,t),getGlobalMouseBlock:()=>Z().instance.getGlobalMouseBlock(),getGlobalKeyboardBlock:()=>Z().instance.getGlobalKeyboardBlock(),getGlobalCursorOverride:()=>Z().instance.getGlobalCursorOverride(),getKeyInputBlock:e=>Z().instance.getKeyInputBlock(e)}}}function jn(){return{track:(e,t)=>{let n=q.getInstance();n.track(`custom__${String(e)}`,t)}}}var Mn=xe((exports,t)=>{var n=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),r=n((e,t)=>{var n=new Set([`mouseDown`,`mouseUp`,`pointerDown`,`pointerUp`]),r=new WeakSet;function i(e,t,{allowHosts:i}={}){let{shell:a}=t;if(r.has(e))return;r.add(e);let o=e.webContents;function s(e){return!!(!c(e)||i?.includes(e.host))}function c(e){return new URL(o.getURL()).origin!==e.origin}let l=0;function u(){l=Date.now()}function d(){let e=Date.now()-l,t=e<150;return t||console.warn(`was not recently active`,e),t}if(process.platform===`win32`){let t={KEYDOWN:256,LBUTTONUP:514,MBUTTONUP:520,RBUTTONUP:517,XBUTTONUP:524,TOUCH:576};for(let n of Object.values(t))e.hookWindowMessage(n,u)}o.on(`input-event`,(e,t)=>{n.has(t.type)&&u()}),o.on(`will-navigate`,(e,t)=>{let n=e.url||t;if(console.log(`will-navigate`,n),!n)return;let r=new URL(n);if(!s(r)){if(!d()){console.log(`blocked navigation`,n),e.preventDefault();return}c(r)&&(console.log(`external navigation`,n),e.preventDefault(),a.openExternal(n))}}),o.session.on(`will-download`,(e,t)=>{let n=t.getURL();/^blob:/.test(n)||e.preventDefault()}),o.setWindowOpenHandler(e=>{console.log(`window-open`,e.url);let{url:t}=e,n=new URL(t);if(!s(n))return d()?(c(n)&&a.openExternal(e.url),{action:`deny`}):(console.log(`blocked navigation`,t),{action:`deny`})})}t.exports=i}),i=n((e,t)=>{var n=new Set([`Mozilla`,`AppleWebKit`,`Chrome`,`Safari`,`Gecko`,`Firefox`,`OPR`,`Edg`,`Version`,`Mobile`,`curl`,`PostmanRuntime`]);async function r(e,t,r){let{webContents:i}=e,a=await i.executeJavaScript(`navigator.userAgent`);a=a.match(/[^\/]+\/[^\s]+( \([^\)]+\))?/g).map(e=>e.trim()).filter(e=>{let[t]=e.split(`/`,1);return n.has(t)}).join(` `),i.setUserAgent(a),t.app.userAgentFallback=a}t.exports=r}),a=r(),o=i();function s(e,t,n={}){a(e,t,n.linkHandler),o(e,t,n.userAgent)}t.exports={setupRevUtils:s,setupLinkHandler:a,setUserAgent:o}}),Nn=Ce(Mn(),1);function Pn(){return{registerWindow:e=>{(0,Nn.setupRevUtils)(e,global.OVERLAYED.electron)}}}function Fn(e){let t=nt(global.OVERLAYED.APPLICATION_ID),n=ot(t,{recursive:!0}),r=et(),i=ot(r,{recursive:!0});I.getInstance().info(`Logs path: `,t),I.getInstance().info(`Overlayed logs path: `,r);let a=new g;return[...n,...i].forEach(([e,t])=>{I.getInstance().info(`Zipping: `,t);let n=oe(t),r=m(t);a.file(r,n,{compression:`DEFLATE`})}),Object.entries(e?.additionalFiles??{}).forEach(([e,t])=>{I.getInstance().info(`Zipping extra file: `,e),a.file(e,t,{compression:`DEFLATE`})}),a}async function In(e,t){let n={...e,version:`${global.OVERLAYED.APP_VERSION}@${global.OVERLAYED.APP_BUILD_CHANNEL}`,log_zip:`data:application/zip;base64,${t}`};await fetch(`https://api.stats.cc/v1/overlay/contact`,{method:`POST`,body:JSON.stringify(n),redirect:`follow`,headers:{"Content-Type":`application/json`}})}function Ln(e){let t=new it(`app.log`);return t.init(global.OVERLAYED.APPLICATION_ID,e.debug),{scope:e=>t.scope(e),info:e=>t.info(e),warn:e=>t.warn(e),error:e=>t.error(e),debug:e=>t.debug(e),submitBugReport:async(e,t)=>{q.getInstance().track(`bug_report_submitted`,{version:e.version,category:e.category});let n=Fn(t),r=await n.generateAsync({type:`base64`});await In(e,r)}}}const Rn=1e3;function zn(e,t,r,i,a){let o=L.getInstance();function s(e,t){let n=r.get(t);if(!n)r.set(t,[e]);else{if(n.length>=Rn){P.getInstance().warn(`Event buffer full, removing oldest event`,`EVENT_BUFFER_FULL`,{summary:`Event buffer overflow for module ${t}. Buffer size: ${n.length}, max: ${Rn}`});return}n.push(e)}}function c(r){let i=mn(r);if(i instanceof n.errors){q.getInstance().track(`invalid_game_event`,{}),P.getInstance().warn(`Invalid event`,`INVALID_EVENT`,{summary:i.summary});return}let o=e.modules.find(e=>e.key===i.game);if(!o)return;let c=o.events.event,l=c(r);if(l instanceof n.errors){q.getInstance().track(`invalid_game_event`,{game:i.game,type:i.type}),P.getInstance().warn(`Invalid event`,`INVALID_EVENT`,{summary:l.summary});return}if(!a[o.key]){s(l,o.key);return}if(l.type===`unsupported_game_version`){let{content:e}=l;q.getInstance().track(`unsupported_game_version`,{game:l.game,hash:e?.hash,version:e?.version})}let u=Y(o.key,l.type),d=Y(o.key,`*`),f=t.get(u),p=t.get(d),m=[...Array.from(f??[]),...Array.from(p??[])];m.length!==0&&m.forEach(e=>{e(l)})}return i.on(`flushEvents`,e=>{if(a[e])return;a[e]=!0;let t=r.get(e);t&&(I.getInstance().info(`Flushing ${t.length} events for module ${e}`),t.forEach(e=>c(e)),r.delete(e))}),o.on(`data`,e=>e.forEach(c)),o.on(`error`,e=>{P.getInstance().error(`Pipe server error`,`PIPE_SERVER_ERROR`,{error:e})}),o}let Q=!1,Bn={},$,Vn=new M;function Hn(e){let{init:t=!0,debug:n=!1,silent:r=!0}=e;if(Un(e),I.getInstance().init(e.applicationId,n,r),Q)return $;function i(){if(Q)return;Tn();let t=new Map,n=new Map,r=vn(e.modules,t,Vn),a=yn(),o=wn(e.keybinds),s=Dn(),c=An(),l=Pn(),u=jn(),d=Ln(e);Wn(e),zn(e,t,n,Vn,Bn),Q=!0,$={...r,...a,ads:l,keybinds:o,windows:s,input:c,cortex:u,hasAnyActiveProcesses:()=>G.getInstance().hasAnyActiveProcesses,init:i,log:d,initialized:Q}}return t?(i(),$):new Proxy({init:i},{get:(e,t)=>{if(t!==`init`&&!Q)throw Error(`overlayed was called before initialized: ${t}`);return t===`init`?e[t]:$[t]}})}global.OVERLAYED=new Proxy({},{get:()=>{throw Error(`function overlayed was not called`)}});function Un(e){global.OVERLAYED={APPLICATION_ID:Ot(e.applicationId),APP_BUILD_CHANNEL:e.channel??`alpha`,APP_VERSION:e.version??`0.0.0`,PACKAGE_VERSION:`0.18.4`,FRONTEND_VERSION:`0.0.0`,sessionId:crypto.randomUUID(),electron:e.electron}}function Wn(e){let t=e.universal?[`*`]:e.modules.map(e=>e.key);J.getInstance().setSubscribedGames(t),fn.getInstance().init(),J.getInstance().init(),G.getInstance().init(),U.getInstance().init();async function n(){let e=kt(global.OVERLAYED.APPLICATION_ID).then(e=>e.data),t=gn();I.getInstance().log(`userId`,t);let n={...await e,userId:t};return I.getInstance().log(`appInfo`,n),n}let r;global.OVERLAYED.electron.ipcMain.handle(`getAppInfo`,async()=>(r=r??n(),r)),q.getInstance().track(`start`,{}),me.on(`quit`,()=>{q.getInstance().track(`electron_quit`,{}),Gn()}),process.on(`exit`,()=>{q.getInstance().track(`exit`,{}),Gn()})}async function Gn(){await q.getInstance().flush(),U.getInstance().destroy(),J.getInstance().destroy(),fn.getInstance().destroy(),G.getInstance().destroy(),K.getInstance().getInterface(`OGG_SIEGE`).destroy(),L.getInstance().destroy(),P.getInstance().destroy()}export{lt as defineConfig,Hn as overlayed,Ut as setFetchLatestTokenCallback,Ct as setUpdaterTokenResolver};