@overlayed/app 0.34.7 → 0.34.8

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.
Files changed (2) hide show
  1. package/dist/index.mjs +1 -5
  2. package/package.json +1 -1
package/dist/index.mjs CHANGED
@@ -1,5 +1 @@
1
- import{createRequire as e}from"node:module";import{Type as t,scope as n,type as r}from"arktype";import i from"mitt";import a,{createWriteStream as o,existsSync as s,mkdirSync as c,readdirSync as l,unlinkSync as u,writeFileSync as d}from"fs";import{ensureFileSync as f}from"fs-extra";import{join as p}from"path";import m,{basename as ee,resolve as te}from"node:path";import h from"node:process";import*as g from"node:os";import ne from"node:os";import re from"node:tty";import ie from"events";import{copyFileSync as ae,createReadStream as oe,existsSync as _,mkdirSync as se,readFileSync as ce,readdirSync as le,writeFileSync as ue}from"node:fs";import"glob";import"jiti";import de from"xior";import v from"fs/promises";import fe from"jszip";import{createHash as pe}from"node:crypto";import{app as me}from"electron";import*as he from"node:fs/promises";import ge from"systeminformation";var _e=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports);function ve(e){return e}function y(e){return e?Array.isArray(e)?e:[e]:[]}function ye(e){return typeof e==`string`&&/^01[0-9A-HJKMNP-TV-Z]{24}$/.test(e)}var be=class{data=[];constructor(){}get size(){return this.data.length}add(e){this.data.push(e)}next(){return this.data.shift()}clear(){this.data.length=0}*flush(){for(;this.size>0;){let e=this.next();e&&(yield e)}}};const xe=(e=0)=>t=>`\u001B[${t+e}m`,Se=(e=0)=>t=>`\u001B[${38+e};5;${t}m`,Ce=(e=0)=>(t,n,r)=>`\u001B[${38+e};2;${t};${n};${r}m`,b={modifier:{reset:[0,0],bold:[1,22],dim:[2,22],italic:[3,23],underline:[4,24],overline:[53,55],inverse:[7,27],hidden:[8,28],strikethrough:[9,29]},color:{black:[30,39],red:[31,39],green:[32,39],yellow:[33,39],blue:[34,39],magenta:[35,39],cyan:[36,39],white:[37,39],blackBright:[90,39],gray:[90,39],grey:[90,39],redBright:[91,39],greenBright:[92,39],yellowBright:[93,39],blueBright:[94,39],magentaBright:[95,39],cyanBright:[96,39],whiteBright:[97,39]},bgColor:{bgBlack:[40,49],bgRed:[41,49],bgGreen:[42,49],bgYellow:[43,49],bgBlue:[44,49],bgMagenta:[45,49],bgCyan:[46,49],bgWhite:[47,49],bgBlackBright:[100,49],bgGray:[100,49],bgGrey:[100,49],bgRedBright:[101,49],bgGreenBright:[102,49],bgYellowBright:[103,49],bgBlueBright:[104,49],bgMagentaBright:[105,49],bgCyanBright:[106,49],bgWhiteBright:[107,49]}};Object.keys(b.modifier);const we=Object.keys(b.color),Te=Object.keys(b.bgColor);[...we,...Te];function Ee(){let e=new Map;for(let[t,n]of Object.entries(b)){for(let[t,r]of Object.entries(n))b[t]={open:`\u001B[${r[0]}m`,close:`\u001B[${r[1]}m`},n[t]=b[t],e.set(r[0],r[1]);Object.defineProperty(b,t,{value:n,enumerable:!1})}return Object.defineProperty(b,`codes`,{value:e,enumerable:!1}),b.color.close=`\x1B[39m`,b.bgColor.close=`\x1B[49m`,b.color.ansi=xe(),b.color.ansi256=Se(),b.color.ansi16m=Ce(),b.bgColor.ansi=xe(10),b.bgColor.ansi256=Se(10),b.bgColor.ansi16m=Ce(10),Object.defineProperties(b,{rgbToAnsi256:{value(e,t,n){return e===t&&t===n?e<8?16:e>248?231:Math.round((e-8)/247*24)+232:16+36*Math.round(e/255*5)+6*Math.round(t/255*5)+Math.round(n/255*5)},enumerable:!1},hexToRgb:{value(e){let t=/[a-f\d]{6}|[a-f\d]{3}/i.exec(e.toString(16));if(!t)return[0,0,0];let[n]=t;n.length===3&&(n=[...n].map(e=>e+e).join(``));let r=Number.parseInt(n,16);return[r>>16&255,r>>8&255,r&255]},enumerable:!1},hexToAnsi256:{value:e=>b.rgbToAnsi256(...b.hexToRgb(e)),enumerable:!1},ansi256ToAnsi:{value(e){if(e<8)return 30+e;if(e<16)return 90+(e-8);let t,n,r;if(e>=232)t=((e-232)*10+8)/255,n=t,r=t;else{e-=16;let i=e%36;t=Math.floor(e/36)/5,n=Math.floor(i/6)/5,r=i%6/5}let i=Math.max(t,n,r)*2;if(i===0)return 30;let a=30+(Math.round(r)<<2|Math.round(n)<<1|Math.round(t));return i===2&&(a+=60),a},enumerable:!1},rgbToAnsi:{value:(e,t,n)=>b.ansi256ToAnsi(b.rgbToAnsi256(e,t,n)),enumerable:!1},hexToAnsi:{value:e=>b.ansi256ToAnsi(b.hexToAnsi256(e)),enumerable:!1}}),b}var x=Ee();function S(e,t=globalThis.Deno?globalThis.Deno.args:h.argv){let n=e.startsWith(`-`)?``:e.length===1?`-`:`--`,r=t.indexOf(n+e),i=t.indexOf(`--`);return r!==-1&&(i===-1||r<i)}const{env:C}=h;let w;S(`no-color`)||S(`no-colors`)||S(`color=false`)||S(`color=never`)?w=0:(S(`color`)||S(`colors`)||S(`color=true`)||S(`color=always`))&&(w=1);function De(){if(`FORCE_COLOR`in C)return C.FORCE_COLOR===`true`?1:C.FORCE_COLOR===`false`?0:C.FORCE_COLOR.length===0?1:Math.min(Number.parseInt(C.FORCE_COLOR,10),3)}function Oe(e){return e===0?!1:{level:e,hasBasic:!0,has256:e>=2,has16m:e>=3}}function ke(e,{streamIsTTY:t,sniffFlags:n=!0}={}){let r=De();r!==void 0&&(w=r);let i=n?w:r;if(i===0)return 0;if(n){if(S(`color=16m`)||S(`color=full`)||S(`color=truecolor`))return 3;if(S(`color=256`))return 2}if(`TF_BUILD`in C&&`AGENT_NAME`in C)return 1;if(e&&!t&&i===void 0)return 0;let a=i||0;if(C.TERM===`dumb`)return a;if(h.platform===`win32`){let e=ne.release().split(`.`);return Number(e[0])>=10&&Number(e[2])>=10586?Number(e[2])>=14931?3:2:1}if(`CI`in C)return[`GITHUB_ACTIONS`,`GITEA_ACTIONS`,`CIRCLECI`].some(e=>e in C)?3:[`TRAVIS`,`APPVEYOR`,`GITLAB_CI`,`BUILDKITE`,`DRONE`].some(e=>e in C)||C.CI_NAME===`codeship`?1:a;if(`TEAMCITY_VERSION`in C)return/^(9\.(0*[1-9]\d*)\.|\d{2,}\.)/.test(C.TEAMCITY_VERSION)?1:0;if(C.COLORTERM===`truecolor`||C.TERM===`xterm-kitty`||C.TERM===`xterm-ghostty`||C.TERM===`wezterm`)return 3;if(`TERM_PROGRAM`in C){let e=Number.parseInt((C.TERM_PROGRAM_VERSION||``).split(`.`)[0],10);switch(C.TERM_PROGRAM){case`iTerm.app`:return e>=3?3:2;case`Apple_Terminal`:return 2}}return/-256(color)?$/i.test(C.TERM)?2:/^screen|^xterm|^vt100|^vt220|^rxvt|color|ansi|cygwin|linux/i.test(C.TERM)||`COLORTERM`in C?1:a}function Ae(e,t={}){return Oe(ke(e,{streamIsTTY:e&&e.isTTY,...t}))}var je={stdout:Ae({isTTY:re.isatty(1)}),stderr:Ae({isTTY:re.isatty(2)})};function Me(e,t,n){let r=e.indexOf(t);if(r===-1)return e;let i=t.length,a=0,o=``;do o+=e.slice(a,r)+t+n,a=r+i,r=e.indexOf(t,a);while(r!==-1);return o+=e.slice(a),o}function Ne(e,t,n,r){let i=0,a=``;do{let o=e[r-1]===`\r`;a+=e.slice(i,o?r-1:r)+t+(o?`\r
2
- `:`
3
- `)+n,i=r+1,r=e.indexOf(`
4
- `,i)}while(r!==-1);return a+=e.slice(i),a}const{stdout:Pe,stderr:Fe}=je,Ie=Symbol(`GENERATOR`),T=Symbol(`STYLER`),E=Symbol(`IS_EMPTY`),Le=[`ansi`,`ansi`,`ansi256`,`ansi16m`],D=Object.create(null),Re=(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=Pe?Pe.level:0;e.level=t.level===void 0?n:t.level},ze=e=>{let t=(...e)=>e.join(` `);return Re(t,e),Object.setPrototypeOf(t,O.prototype),t};function O(e){return ze(e)}Object.setPrototypeOf(O.prototype,Function.prototype);for(let[e,t]of Object.entries(x))D[e]={get(){let n=A(this,k(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 Be=(e,t,n,...r)=>e===`rgb`?t===`ansi16m`?x[n].ansi16m(...r):t===`ansi256`?x[n].ansi256(x.rgbToAnsi256(...r)):x[n].ansi(x.rgbToAnsi(...r)):e===`hex`?Be(`rgb`,t,n,...x.hexToRgb(...r)):x[n][e](...r);for(let e of[`rgb`,`hex`,`ansi256`]){D[e]={get(){let{level:t}=this;return function(...n){let r=k(Be(e,Le[t],`color`,...n),x.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=k(Be(e,Le[t],`bgColor`,...n),x.bgColor.close,this[T]);return A(this,r,this[E])}}}}const Ve=Object.defineProperties(()=>{},{...D,level:{enumerable:!0,get(){return this[Ie].level},set(e){this[Ie].level=e}}}),k=(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)=>He(r,e.length===1?``+e[0]:e.join(` `));return Object.setPrototypeOf(r,Ve),r[Ie]=e,r[T]=t,r[E]=n,r},He=(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=Me(t,n.close,n.open),n=n.parent;let a=t.indexOf(`
5
- `);return a!==-1&&(t=Ne(t,i,r,a)),r+t+i};Object.defineProperties(O.prototype,D);const Ue=O();O({level:Fe?Fe.level:0});var j=Ue,M=class{emitter;constructor(){this.emitter=i()}on(e,t){y(e).forEach(e=>{this.emitter.on(e,t)})}off(e,t){y(e).forEach(e=>{this.emitter.off(e,t)})}emit(e,t){y(e).forEach(e=>{this.emitter.emit(e,t)})}removeAllListeners(){this.emitter.all.clear()}},We=class{listeners;constructor(){this.listeners=new Map}on(e,t){y(e).forEach(e=>{let n=this.listeners.get(e)||new Set;n.add(t),this.listeners.set(e,n)})}off(e,t){y(e).forEach(e=>{let n=this.listeners.get(e);n&&n.delete(t)})}async emit(e,...t){let n=y(e).flatMap(e=>{let t=this.listeners.get(e)||new Set,n=this.listeners.get(`*`)||new Set;return[...Array.from(t),...Array.from(n)]});return n.length===0?[]: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}}))}removeAllListeners(){this.listeners.clear()}};function N(e,...t){return class extends e{static _instance;static getInstance(){return this._instance||=new e(...t),this._instance}static clearInstance(){this._instance=void 0}}}const P=N(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()})}});var F=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){return this.get()[e]}save(e){let t=this.onBeforeSave(e);try{f(this.getFilePath()),a.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=a.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=r(`string.json.parse`).to(`object`)(e);if(t instanceof r.errors)return this._defaultValue;let n=this._schema[`~standard`].validate(t);if(n instanceof Promise)throw Error(`StructuredConfigFile does not support async validation`);return n.issues?this.migrate(t,this._defaultValue):this.migrate(n.value,this._defaultValue)}catch{return this._defaultValue}}canReadWriteFile(e){try{return a.accessSync(e,a.constants.R_OK|a.constants.W_OK),!0}catch{return!1}}fileExists(e){try{return a.accessSync(e,a.constants.F_OK),!0}catch{return!1}}migrate(e,t){let n={...e};for(let r in t)Object.prototype.hasOwnProperty.call(t,r)&&(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})}};function Ge(e,t,n){return typeof e!=`object`||!e?String(e):e instanceof Error?JSON.stringify(e,Object.getOwnPropertyNames(e),n):e instanceof Map?JSON.stringify(Object.fromEntries(e.entries()),t,n):e instanceof Set?JSON.stringify(Array.from(e),t,n):JSON.stringify(e,t,n)}var Ke=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(`info`,...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;return{timestamp:n.toISOString().replace(`T`,` `).replace(/\.\d+Z$/,``)+`.${n.getUTCMilliseconds().toString().padStart(3,`0`)}`,level:e,message:t.map(e=>Ge(e)).join(` `)}}getFileName(e){return`${this.baseFileName}-${e}.log`}ensureLogDirectory(){try{c(this.logPath,{recursive:!0})}catch(e){throw console.error(`Failed to create log directory ${this.logPath}:`,e),e}}ensureLogFile(){let e=p(this.logPath,this.getFileName(this.currentDate));if(!s(e))try{d(e,``,`utf8`)}catch(t){throw console.error(`Failed to create log file ${e}:`,t),t}}getDateString(e){return`${e.getUTCFullYear()}-${(e.getUTCMonth()+1).toString().padStart(2,`0`)}-${e.getUTCDate().toString().padStart(2,`0`)}`}createStream(){return o(p(this.logPath,this.getFileName(this.currentDate)),{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=l(this.logPath),t=new Date,n=new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()-7));e.filter(e=>e.startsWith(this.baseFileName)&&e.endsWith(`.log`)).filter(e=>{let[t,r,i]=e.replace(`${this.baseFileName}-`,``).replace(`.log`,``).split(`-`).map(Number);return new Date(Date.UTC(t,r-1,i))<=n}).forEach(e=>{try{u(p(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 I=()=>m.join(process.env.APPDATA??``,`overlayed`),qe=()=>m.join(I(),`logs`),Je=e=>m.join(I(),`apps`,e),Ye=e=>m.join(Je(e),`logs`),Xe=()=>m.join(I(),`meta.json`);var Ze=class{fileLogger;path;appId;messageQueue=new be;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=Ye(e),this.fileLogger=new Ke(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}=Ke.getMessageElements(e,...t),a=console[e],o=n[e];a(`${j.gray(r)} ${o(i)}`)}};const L=N(Ze,`overlayed.log`);var Qe=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=new Map,i=new Set,a=new Set,o=[];for(let e=0;e<n;e++)o.push(e);let s=async n=>{let s=n*t,c=Math.min(s+t,this.blob.size),l=this.blob.slice(s,c);try{await e(l,n),a.add(n),this.emit(`chunkComplete`,n),i.delete(n)}catch(e){let t=r.get(n)||0;t<5?(r.set(n,t+1),await new Promise(e=>setTimeout(e,(t+1)*1e3)),o.push(n)):(a.add(n),this.emit(`error`,e),this.shouldStop=!0,i.delete(n))}},c=[],l=async()=>{for(;(o.length>0||i.size>0)&&!this.shouldStop;){if(o.length===0){await new Promise(e=>setTimeout(e,10));continue}let e=o.shift();a.has(e)||i.has(e)||(i.add(e),await s(e))}};for(let e=0;e<this.maxConcurrent;e++)c.push(l());await Promise.all(c)}};function $e(e,t){let{recursive:n}=et(t);return _(e)?n?tt(e).map(t=>[e,t]):le(e).map(t=>[e,t]):[]}function et(e){return{recursive:e?.recursive??!0}}function tt(e){return le(e,{withFileTypes:!0}).flatMap(t=>{let n=m.join(e,t.name);return t.isDirectory()?tt(n):[n]})}function nt(e){return rt(e),e}function rt(e){if(!ye(e.applicationId))throw Error(`Invalid applicationId, must be a valid ULID.`)}const{PipeEventServer:it,PipeEventClient:at,PipeEventBase:ot,ProcessMonitor:st,Process:ct,HardwareInterface:lt}=e(import.meta.url)(`@overlayed/app/dist/native-interface/build/overlayed_native_interface_x64.node`),ut=N(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(),null)}init(){this.server=new it(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})}},`overlayed-event-server`),{RenderInterface:dt,renderHookPath:ft}=e(import.meta.url)(`@overlayed/app/dist/render-interface/build/overlayed_render_interface_x64.node`);let pt=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}({});const R=r({game:`string`,type:`string`,creation_time:`number`}).and({game:`'siege' | 'tft'`}),mt=R.and({type:`'logged_in'`,content:{account_id:`string`}}),ht=R.and({type:`'module_loaded'`,content:{game_version:`string`,process_hash:`string`}}),gt=R.and({type:`'module_unloaded'`}),_t=R.and({type:`'unsupported_game_version'`,content:{game_version:`string`,process_hash:`string`}}),vt=n({"#event1":`logged_in | module_loaded | module_unloaded | unsupported_game_version`,event:`event1`,logged_in:mt,module_loaded:ht,module_unloaded:gt,unsupported_game_version:_t}).export(),yt=Object.keys(vt).filter(e=>e!==`event`);function bt(){return{key:`universal`,events:vt}}var xt=class{logger;initialized=!1;constructor(e){this.logger=L.getInstance().scope(e)}init(){this.logger.log(`Initializing`),this.initialized=!0}destroy(){this.logger.log(`Destroying`),this.initialized=!1}},z=class extends M{logger;initialized=!1;constructor(e){super(),this.logger=L.getInstance().scope(e)}init(){this.logger.log(`Initializing`),this.initialized=!0}destroy(){this.logger.log(`Destroying`),this.initialized=!1,this.removeAllListeners()}},St=class extends We{logger;initialized=!1;constructor(e){super(),this.logger=L.getInstance().scope(e)}init(){this.logger.log(`Initializing`),this.initialized=!0}destroy(){this.logger.log(`Destroying`),this.initialized=!1,this.removeAllListeners()}};const Ct=de.create({baseURL:`https://updater.stats.cc`,headers:{Accept:`application/json`,"Accept-Encoding":`gzip, deflate, br`}});let wt;function Tt(e){wt=e}Ct.interceptors.request.use(e=>{let t=wt?.();return t?(e.headers??={},e.headers.Authorization=t,e):e});const B=de.create({baseURL:`https://api.overlayed.gg`,headers:{Accept:`application/json`,"Accept-Encoding":`gzip, deflate, br`}});let Et;function Dt(e){Et=e}function Ot(e){return`overlayed/app (${Object.entries(e).map(([e,t])=>`${e}=${t}`).join(`; `)})`}B.interceptors.request.use(e=>{e.headers??={};let t=Et?.();return t&&(e.headers[`User-Agent`]=Ot(t)),e});function kt(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 At(e){return e}function jt(e){return e?t=>(e(t),t):At}const Mt=jt();function Nt(e){return B.get(`/v1/public/applications/${e}`)}function Pt(e,t){let n=new FormData;return n.append(`file`,new Blob([t.file],{type:`application/zip`}),`logs.zip`),n.append(`data`,JSON.stringify(t.data)),B.post(`/v1/public/applications/${e}/feedbacks`,n)}function Ft(e,t){return B.get(`/v1/public/applications/${e}/notices`,{params:t})}function It(e,t){return B.get(`/v1/public/modules/${e}/release`,{params:{cortex_user_id:t}})}function Lt(e,t,n){return B.post(`/v1/public/modules/${e}/releases/${t}/download`,{download_token:n})}async function Rt(e,t){if(e.method!==`GET`)throw Error(`Unsupported presigned request method: ${e.method}`);let n=await fetch(e.url,{method:e.method,headers:e.headers,signal:t?.signal});if(!n.ok){let e=await zt(n);throw Error(`Presigned download failed (${n.status} ${n.statusText})${e?`: ${e}`:``}`)}let r=await n.arrayBuffer();return new Uint8Array(r)}async function zt(e){try{let t=(await e.text()).trim();if(t.length===0)return;let n=2048;return t.length>n?`${t.slice(0,n)}…`:t}catch{return}}function Bt(){return B.get(`/v1/public/raven/config`)}function Vt(e,t){return B.get(`/v1/public/raven/games/${e}/builds/${t}`)}function Ht(e,t){return B.post(`/v1/public/raven/games/${e}/builds/upload`,null,{params:t})}function Ut(e,t){let n=new FormData;return n.append(`file`,t.chunk),B.patch(`/v1/public/raven/games/${e}/builds/upload`,n,{params:t})}function Wt(e){let t=Date.now(),n=kt(e.messages.map(e=>Gt(t,e)),250),r=Promise.all(n.map(async t=>B.post(`/v1/public/cortex/events`,{...e,messages:t})));return r.catch(e=>{let t=e?.response?.data||e?.message||e;console.error(`Failed to submit cortex events`,t)}),r}function Gt(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 Kt(e){return e instanceof Error&&(e.name===`XiorError`||e.name===`XiorTimeoutError`)}function qt(e){return!!(e&&`kind`in e.data&&`message`in e.data)}const{PipeEventServer:Jt,PipeEventClient:Yt,PipeEventBase:Xt,ProcessMonitor:Zt,Process:Qt,HardwareInterface:$t}=e(import.meta.url)(`@overlayed/app/dist/native-interface/build/overlayed_native_interface_x64.node`);function en(e=[]){return m.normalize(m.join(Je(global.OVERLAYED.APPLICATION_ID),...e))}const tn=r({game:`string`,type:`string`,creation_time:`number`}),V=new F({path:Xe(),schema:r({userId:`string | undefined`,sessionId:`string | undefined`,sessionLastUsed:`number | undefined`,"debug?":{"ri_disabled?":`boolean`,"gm_disabled?":`boolean`}}),default:{userId:void 0,sessionId:void 0,sessionLastUsed:void 0}});function nn(){let{debug:e}=V.get();return e?{ri_disabled:e.ri_disabled??!1,gm_disabled:e.gm_disabled??!1}:{ri_disabled:!1,gm_disabled:!1}}function rn(){let e=V.get().userId;if(e)return e;let t=sn();return V.set({...V.get(),userId:t}),t}function an(){let e=V.get();if(e.sessionId&&typeof e.sessionLastUsed==`number`&&Date.now()-e.sessionLastUsed<=300*1e3)return e.sessionId;let t=crypto.randomUUID();return V.set({...e,sessionId:t,sessionLastUsed:Date.now()}),t}function on(){try{let e=V.get();V.set({...e,sessionLastUsed:Date.now()})}catch(e){L.getInstance().log(`Failed to update sessionLastUsed`,e)}}function sn(){try{return $t.generateUniqueIdentifier()}catch{return crypto.randomUUID()}}let cn;function ln(e){cn=e}const un=N(class extends z{UPDATE_CHECK_INTERVAL_MS=1e3*60*5;targetDir;updateInterval;constructor(){super(`NativeModuleManager`),this.targetDir=m.join(I(),`resources`),this.logger.log(`Target directory`,this.targetDir)}async initWithDlls(e){super.init(),await v.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),void 0),super.destroy()}async getDllFile(e){let t=await this.getCurrentBuildInfo(e);if(!t){this.logger.error(`No build found for module`,{moduleId:e});return}let n=this.getBuildPath(e,t.buildId);if(!_(n)){this.logger.error(`No build file found for module`,{moduleId:e});return}let r=m.join(n,t.buildFileName);if(!_(r)){this.logger.error(`No DLL file found for module`,{moduleId:e});return}return r}async getCurrentBuildInfo(e){try{let t=m.join(this.targetDir,e,`build.json`),n=await v.readFile(t,`utf-8`);return JSON.parse(n)}catch{return null}}getModulePath(e){return m.join(this.targetDir,e)}getBuildPath(e,t){return m.join(this.getModulePath(e),t)}async checkForUpdates(e){this.logger.log(`Checking for updates`);let t=rn();if(!t){this.logger.error(`Failed to resolve cortex user id`);return}this.logger.log(`Cortex User ID`,t),await cn?.();for(let n of e)try{let{data:e}=await It(n,t);this.logger.log(`Release`,e);let r=(await this.getCurrentBuildInfo(n))?.buildId||null;this.logger.log(`${n} > Performing update check. current: ${r}, requested: ${e.build_id}`),e.build_id!==r||await this.isDownloadCorrupted(this.getBuildPath(n,e.build_id),e)?(this.logger.log(`${n} > Update found. current: ${r}, requested: ${e.build_id}`),this.logger.log(`${n} > Downloading and extracting DLLs`),await this.downloadAndExtractDll(n,e),this.logger.log(`${n} > Cleaning up other builds`),await this.cleanupExistingBuilds(n,e.build_id),this.emit(`dllUpdated`,{moduleId:n,buildId:e.build_id,releaseId:e.release_id})):this.logger.log(`${n} > No update found`)}catch(e){this.logger.error(`${n} > Error checking/updating`,e)}}async downloadAndExtractDll(e,t){this.logger.log(`${e} > Requesting download for build ${t.build_id}`);let{data:n}=await Lt(e,t.release_id,t.download_token);this.logger.log(`${e} > Downloading DLLs for build ${t.build_id}`);let r=await Rt(n,{signal:AbortSignal.timeout(1e3*60*5)});this.logger.log(`${e} > Downloaded zip file for build ${t.build_id}`);let i=this.getBuildPath(e,t.build_id);await v.mkdir(i,{recursive:!0});let a=new fe;await a.loadAsync(r);let o=Object.keys(a.files).map(e=>({name:e,file:a.files[e]})).filter(({file:e})=>!e.dir);if(o.length!==1){this.logger.error(`${e} > Zip must contain exactly 1 file, got ${o.length}`);return}let s=o[0],c=m.basename(s.name),l=m.normalize(c),u=m.isAbsolute(l),d=l.startsWith(`..`)||l.includes(`..${m.sep}`);if(c===``||c===`.`||c===`..`){this.logger.error(`${e} > Zip contained an invalid file name: ${s.name}`);return}if(!c.toLowerCase().endsWith(`.dll`)){this.logger.error(`${e} > Zip contained a non-dll file: ${s.name}`);return}if(u||d){this.logger.error(`${e} > Zip entry path is unsafe: ${s.name}`);return}let f=m.join(i,l),p=await s.file.async(`nodebuffer`);await v.writeFile(f,p),this.logger.log(`${e} > Extracted 1 file to ${f}`);let ee={buildId:t.build_id,buildFileName:t.build_file_name},te=m.join(this.getModulePath(e),`build.json`);await v.writeFile(te,JSON.stringify(ee),`utf-8`),this.logger.log(`${e} > Saved buildId to file: ${t.build_id}`)}async cleanupExistingBuilds(e,t){let n=this.getModulePath(e),r=this.getBuildPath(e,t),i=await v.readdir(n,{withFileTypes:!0});for(let t of i)t.isDirectory()&&m.join(n,t.name)!==r&&(await v.rm(m.join(n,t.name),{recursive:!0,force:!0}),this.logger.log(`${e} > Cleaned up build: ${t.name}`))}async hasPathAccess(e){try{return await v.access(e,v.constants.F_OK),!0}catch{return!1}}async isDownloadCorrupted(e,t){if(!await this.hasPathAccess(e))return this.logger.error(`Download is corrupted. Path does not exist: ${e}`),!0;let n=t.build_file_name,r=m.join(e,n);if(!_(r))return this.logger.error(`Download is corrupted. Build file not found: ${r}`),!0;let i=await v.readFile(r),a=pe(`sha256`).update(i).digest(`hex`);return a.toLowerCase()===t.build_hash.toLowerCase()?!1:(this.logger.error(`Download is corrupted. Build file hash mismatch: ${n} ${a.toLowerCase()} !== ${t.build_hash.toLowerCase()}`),!0)}}),H=N(class extends z{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),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),un.getInstance().destroy(),super.destroy()}async fetchRavenConfig(){try{this._ravenConfig={games:(await Bt()).data.games},this.resetState();let e=new Set;for(let t of this._ravenConfig.games){for(let e of t.executables){let n=e.toLowerCase();this._executableToGameMap.set(n,t),this._executablesArray.push(n)}t.modules.forEach(t=>e.add(t))}await un.getInstance().initWithDlls(Array.from(e)),this.logger.log(`Raven updated, monitoring ${this._executableToGameMap.size} executables`),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=[]}}),U=N(class extends z{_processMonitor;_processes=new Map;boundOnRavenManagerExecutablesUpdated=this.onRavenManagerExecutablesUpdated.bind(this);constructor(){super(`ProcessManager`),this._processMonitor=new Zt}get hasAnyActiveProcesses(){return this.activeProcesses.length>0}get activeProcesses(){return Array.from(this._processes.values()).flat().filter(e=>!e.destroyedAt)}init(){super.init(),H.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(){H.getInstance().off(`executablesUpdated`,this.boundOnRavenManagerExecutablesUpdated),this._processes.clear(),this._processMonitor.removeAllListeners(),super.destroy()}isProcessRunning(e){return this._processes.get(e)?.some(e=>!e.destroyedAt)??!1}onRavenManagerExecutablesUpdated(e){this.logger.log(`Monitoring ${e.executables.length} processes`),e.executables.forEach(e=>{this._processMonitor.isProcessRegistered(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)?.filter(t=>t.id!==e.id)??[];t.length===0?this._processes.delete(e.name):this._processes.set(e.name,t)}});var dn=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}}};const W=N(class{interfaces={};constructor(){}createInterface(e){return this.interfaces[e]||(this.interfaces[e]=new dn(new dt(e,{access:1}))),this.interfaces[e]}getInterface(e){return this.interfaces[e]?this.interfaces[e]:this.createInterface(e)}}),G=N(class{options;eventQueue;meta=null;constructor(e){this.options=this.resolveOptions(e),this.eventQueue=new be,this.setupFlushInterval()}track(e,t){this.eventQueue.add({type:e,properties:t,created_at:new Date})}flush(){let e=Array.from(this.eventQueue.flush()).concat({type:`ping`,properties:{},created_at:new Date});if(!this.meta)throw Error(`Tried to flush Cortex events before meta was set`);try{Wt({...this.meta,messages:e})}catch{}return e}setupFlushInterval(){setInterval(()=>{this.flush()},this.options.batchIntervalSeconds*1e3)}resolveOptions(e){return{batchIntervalSeconds:e?.batchIntervalSeconds??15}}}),fn=e(import.meta.url),pn=fn.resolve(`@overlayed/app/dist/render-interface/build/overlayed_render_hook_x64.dll`),mn=fn.resolve(`@overlayed/app/dist/render-interface/build/overlayed_render_hook_x86.dll`),hn=fn.resolve(`@overlayed/app/dist/native-interface/build/overlayed_native_interface_x64.node`),K=N(class extends St{boundOnProcessCreate=this.onProcessCreate.bind(this);boundOnProcessDestroy=this.onProcessDestroy.bind(this);subscribedGames=new Set;_activeReadyRavenGames={};get isInGame(){return Object.keys(this._activeReadyRavenGames).length>0}constructor(){super(`GameLaunchManager`)}setSubscribedGames(e){this.subscribedGames=new Set(e)}getActiveGames(){return Object.keys(this._activeReadyRavenGames)}init(){super.init(),W.getInstance().createInterface(`OGG_SIEGE`),U.getInstance().on(`create`,this.boundOnProcessCreate),U.getInstance().on(`destroy`,this.boundOnProcessDestroy)}destroy(){U.getInstance().off(`create`,this.boundOnProcessCreate),U.getInstance().off(`destroy`,this.boundOnProcessDestroy),super.destroy()}on(e,t){super.on(e,t);let n=y(e);if(!(n.includes(`gameReady`)||n.includes(`*`))||Object.keys(this._activeReadyRavenGames).length===0)return;let r=t;for(let e of Object.values(this._activeReadyRavenGames))this.logger.log(`Late calling gameReady callback for game`,e.game),r(e)}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(G.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;let r=Qt.currentProcess;if(this.logger.log(`Game Launched`,t),this.logger.log(`Process is elevated: `,e.isElevated),this.logger.log(`Current process is elevated: `,r.isElevated),e.isElevated&&!r.isElevated){P.getInstance().fatal(`Game is elevated but the App is not`,`ELEVATION_MISMATCH`,{appElevated:!!r.isElevated,gameElevated:!!e.isElevated}),this.logger.log(`Game elevated but App is not`,{appElevated:r.isElevated,gameElevated:e.isElevated});return}let{ri_disabled:i,gm_disabled:a}=nn(),o=!1;!i&&t.has_render_support&&t.allow_dll_injections?o=await this.injectRenderInterface(e):this.logger.log(`Skipping render interface injection`,{has_render_support:t.has_render_support,allow_dll_injections:t.allow_dll_injections,ri_disabled:i}),!a&&t.allow_dll_injections?await this.injectGameModules(t,e):this.logger.log(`Skipping game module(s) injection`,{allow_dll_injections:t.allow_dll_injections,gm_disabled:a});let s={game:t.identifier,inGameRenderingSupported:o};this._activeReadyRavenGames[t.identifier]=s,this.logger.debug(`Active ready raven games`,Object.keys(this._activeReadyRavenGames).join(`, `)),this.logger.log(`Game Ready`),this.emit(`gameReadyInternal`,{ravenGame:t,process:e}),this.emit(`gameReady`,s),G.getInstance().track(`game_ready`,{game:t.identifier})}copyDll(e){let t=m.basename(e),n=te(e),r=m.join(I(),`resources`),i=m.join(r,t);this.logger.info(`Copying`,n,`to`,i);try{_(r)||se(r,{recursive:!0}),ue(i,ce(n)),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 injectRenderInterface(e){this.logger.log(`Injecting render interface`,{is32Bit:e.is32Bit,process:e});let t=e.is32Bit?mn:pn;this.logger.log(`Render hook path`,t);let n=this.copyDll(t);if(!n)return this.logger.error(`Failed to copy render hook DLL`,{renderHookPath:t}),!1;let r=m.join(m.dirname(hn));if(!_(r))return this.logger.error(`Failed to find injector path`,{injectorPath:r}),!1;this.logger.log(`Resolved injector path`,r);try{return this.logger.log(`Injecting render interface`,n),await e.injectDll(n,r),this.logger.log(`Render Interface Injection Successful`,n),!0}catch(e){return this.logger.error(`Render Interface Injection Failed`,e),this.logger.error(`Render Interface Injection Failed`,{renderHookPathCopied:n}),!1}}async injectGameModules(e,t){let n=m.join(m.dirname(hn));if(!_(n)){this.logger.error(`Failed to find injector path`,{injectorPath:n});return}this.logger.log(`Resolved injector path`,n);for(let r of e.modules){let e=await un.getInstance().getDllFile(r);if(!e){this.logger.error(`No DLL file found for module`,{moduleId:r});continue}try{this.logger.log(`Injecting game module`,e),await t.injectDll(e,n),this.logger.log(`Injection Successful`,e)}catch(t){this.logger.error(`Injection Failed`,{dllFile:e},t)}}}onProcessDestroy({process:e}){let t=this.getRavenGame(e);t&&(delete this._activeReadyRavenGames[t.identifier],this.logger.debug(`Active ready raven games`,Object.keys(this._activeReadyRavenGames).join(`, `)),this.emit(`gameCloseInternal`,{ravenGame:t,process:e}),this.emit(`gameClose`,{game:t.identifier}),G.getInstance().track(`game_close`,{game:t.identifier}))}getRavenGame(e){if(!e.name)return;let t=H.getInstance().getExecutableData(e.name);if(!t){this.logger.error(`No raven game found for process`,{process:e});return}return t}}),gn=N(class extends xt{boundOnGameLaunch=this.onGameLaunch.bind(this);constructor(){super(`GameBuildManager`)}init(){super.init(),K.getInstance().on(`gameReadyInternal`,this.boundOnGameLaunch)}destroy(){K.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=ce(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{a=(await Vt(t.identifier,i)).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 fe;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 Qe(s,{chunkSizeMb:25,maxConcurrent:1}),n=await Ht(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 Ut(t.identifier,{chunk:e,build_hash:i,chunk_index:r,upload_token:n.data.upload_token})}),this.logger.log(`Build uploaded successfully`)}catch(e){Kt(e)?qt(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)}}});function q(e,t){return`${e}:${t}`}function _n(e,t,n){return e.reduce((e,r)=>{let i=r.key;return e[i]={on(e,n){let r=q(i,e),a=t.get(r)??new Set;a.add(n),t.set(r,a)},onAny(e){let n=q(i,`*`),r=t.get(n)??new Set;r.add(e),t.set(n,r)},off(e,n){let r=q(i,e),a=t.get(r);a&&(a.delete(n),a.size===0&&t.delete(r))},offAny(e){let n=q(i,`*`),r=t.get(n);r&&(r.delete(e),r.size===0&&t.delete(n))},readyForGameEvents:()=>{n.emit(`flushEvents`,i)}},e},{})}function vn(){let e=P.getInstance(),t=K.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 J=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}(J||{});const yn=new Map([[J.LeftButton,`LeftButton`],[J.RightButton,`RightButton`],[J.Cancel,`Cancel`],[J.MiddleButton,`MiddleButton`],[J.ExtraButton1,`ExtraButton1`],[J.ExtraButton2,`ExtraButton2`],[J.Back,`Backspace`],[J.Tab,`Tab`],[J.Clear,`Clear`],[J.Return,`Enter`],[J.Shift,`ShiftLeft`],[J.Control,`ControlLeft`],[J.Menu,`AltLeft`],[J.Pause,`Pause`],[J.CapsLock,`CapsLock`],[J.Kana,`KanaMode`],[J.Junja,`JunjaMode`],[J.Final,`Finalize`],[J.Hanja,`HanjaMode`],[J.Escape,`Escape`],[J.Convert,`Convert`],[J.NonConvert,`NonConvert`],[J.Accept,`Accept`],[J.ModeChange,`ModeChange`],[J.Space,`Space`],[J.Prior,`PageUp`],[J.Next,`PageDown`],[J.End,`End`],[J.Home,`Home`],[J.Left,`ArrowLeft`],[J.Up,`ArrowUp`],[J.Right,`ArrowRight`],[J.Down,`ArrowDown`],[J.Select,`Select`],[J.Print,`PrintScreen`],[J.Execute,`Execute`],[J.Snapshot,`Snapshot`],[J.Insert,`Insert`],[J.Delete,`Delete`],[J.Help,`Help`],[J.N0,`Digit0`],[J.N1,`Digit1`],[J.N2,`Digit2`],[J.N3,`Digit3`],[J.N4,`Digit4`],[J.N5,`Digit5`],[J.N6,`Digit6`],[J.N7,`Digit7`],[J.N8,`Digit8`],[J.N9,`Digit9`],[J.A,`KeyA`],[J.B,`KeyB`],[J.C,`KeyC`],[J.D,`KeyD`],[J.E,`KeyE`],[J.F,`KeyF`],[J.G,`KeyG`],[J.H,`KeyH`],[J.I,`KeyI`],[J.J,`KeyJ`],[J.K,`KeyK`],[J.L,`KeyL`],[J.M,`KeyM`],[J.N,`KeyN`],[J.O,`KeyO`],[J.P,`KeyP`],[J.Q,`KeyQ`],[J.R,`KeyR`],[J.S,`KeyS`],[J.T,`KeyT`],[J.U,`KeyU`],[J.V,`KeyV`],[J.W,`KeyW`],[J.X,`KeyX`],[J.Y,`KeyY`],[J.Z,`KeyZ`],[J.LeftWindows,`MetaLeft`],[J.RightWindows,`MetaRight`],[J.Application,`ContextMenu`],[J.Sleep,`Sleep`],[J.Numpad0,`Numpad0`],[J.Numpad1,`Numpad1`],[J.Numpad2,`Numpad2`],[J.Numpad3,`Numpad3`],[J.Numpad4,`Numpad4`],[J.Numpad5,`Numpad5`],[J.Numpad6,`Numpad6`],[J.Numpad7,`Numpad7`],[J.Numpad8,`Numpad8`],[J.Numpad9,`Numpad9`],[J.Multiply,`NumpadMultiply`],[J.Add,`NumpadAdd`],[J.Separator,`NumpadSeparator`],[J.Subtract,`NumpadSubtract`],[J.Decimal,`NumpadDecimal`],[J.Divide,`NumpadDivide`],[J.F1,`F1`],[J.F2,`F2`],[J.F3,`F3`],[J.F4,`F4`],[J.F5,`F5`],[J.F6,`F6`],[J.F7,`F7`],[J.F8,`F8`],[J.F9,`F9`],[J.F10,`F10`],[J.F11,`F11`],[J.F12,`F12`],[J.F13,`F13`],[J.F14,`F14`],[J.F15,`F15`],[J.F16,`F16`],[J.F17,`F17`],[J.F18,`F18`],[J.F19,`F19`],[J.F20,`F20`],[J.F21,`F21`],[J.F22,`F22`],[J.F23,`F23`],[J.F24,`F24`],[J.NumLock,`NumLock`],[J.ScrollLock,`ScrollLock`],[J.NEC_Equal,`NEC_Equal`],[J.Fujitsu_Masshou,`Fujitsu_Masshou`],[J.Fujitsu_Touroku,`Fujitsu_Touroku`],[J.Fujitsu_Loya,`Fujitsu_Loya`],[J.Fujitsu_Roya,`Fujitsu_Roya`],[J.LeftShift,`ShiftLeft`],[J.RightShift,`ShiftRight`],[J.LeftControl,`ControlLeft`],[J.RightControl,`ControlRight`],[J.LeftMenu,`AltLeft`],[J.RightMenu,`AltRight`],[J.BrowserBack,`BrowserBack`],[J.BrowserForward,`BrowserForward`],[J.BrowserRefresh,`BrowserRefresh`],[J.BrowserStop,`BrowserStop`],[J.BrowserSearch,`BrowserSearch`],[J.BrowserFavorites,`BrowserFavorites`],[J.BrowserHome,`BrowserHome`],[J.VolumeMute,`VolumeMute`],[J.VolumeDown,`VolumeDown`],[J.VolumeUp,`VolumeUp`],[J.MediaNextTrack,`MediaTrackNext`],[J.MediaPrevTrack,`MediaTrackPrevious`],[J.MediaStop,`MediaStop`],[J.MediaPlayPause,`MediaPlayPause`],[J.LaunchMail,`LaunchMail`],[J.LaunchMediaSelect,`LaunchMediaSelect`],[J.LaunchApplication1,`LaunchApplication1`],[J.LaunchApplication2,`LaunchApplication2`],[J.OEM1,`OEM_1`],[J.OEMPlus,`Equal`],[J.OEMComma,`Comma`],[J.OEMMinus,`Minus`],[J.OEMPeriod,`Period`],[J.OEM2,`Slash`],[J.OEM3,`Backquote`],[J.OEM4,`BracketLeft`],[J.OEM5,`Backslash`],[J.OEM6,`BracketRight`],[J.OEM7,`Quote`],[J.OEM8,`IntlRo`],[J.OEMAX,`OEM_AX`],[J.OEM102,`IntlBackslash`],[J.ICOHelp,`ICO_HELP`],[J.ICO00,`ICO_00`],[J.ProcessKey,`Process`],[J.ICOClear,`ICO_CLEAR`],[J.Packet,`Packet`],[J.OEMReset,`OEM_Reset`],[J.OEMJump,`OEM_Jump`],[J.OEMPA1,`OEM_PA1`],[J.OEMPA2,`OEM_PA2`],[J.OEMPA3,`OEM_PA3`],[J.OEMWSCtrl,`OEM_WS_Ctrl`],[J.OEMCUSel,`OEM_CU_Sel`],[J.OEMATTN,`OEM_ATTN`],[J.OEMFinish,`OEM_Finish`],[J.OEMCopy,`OEM_Copy`],[J.OEMAuto,`OEM_Auto`],[J.OEMENLW,`OEM_ENLW`],[J.OEMBackTab,`BackTab`],[J.ATTN,`ATTN`],[J.CRSel,`CRSel`],[J.EXSel,`EXSel`],[J.EREOF,`EREOF`],[J.Play,`MediaPlay`],[J.Zoom,`Zoom`],[J.Noname,`Noname`],[J.PA1,`PA1`],[J.OEMClear,`OEM_Clear`]]),bn=new Map(yn.entries().map(([e,t])=>[t,e])),xn=r({"[string]":{keys:`string[]`,mode:r(`'toggle' | 'hold'`).pipe(e=>e??`toggle`)}});var Sn=class extends z{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 F({path:en([`keybinds.json`]),schema:xn,default:e})}init(){super.init();let e=W.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)??{toggle:[],down:[],up:[]};n.toggle.push(t),this.preferencesKeybindToCallbacks.set(e,n)}async onKeybindDown(e,t){let n=this.preferencesKeybindToCallbacks.get(e)??{toggle:[],down:[],up:[]};n.down.push(t),this.preferencesKeybindToCallbacks.set(e,n)}async onKeybindUp(e,t){let n=this.preferencesKeybindToCallbacks.get(e)??{toggle:[],down:[],up:[]};n.up.push(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=W.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=yn.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=yn.get(e.key);if(!t)return;this.pressedKeys.delete(t);let n=this.keybindsFile.get();for(let[e]of this.preferencesKeybindToCallbacks.entries())n[e].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||n.up.length===0)continue;let r=e[t];if(this.activeKeybinds.has(t)&&r.keys.some(e=>!this.pressedKeys.has(e))){this.activeKeybinds.delete(t);for(let e of n.up)e();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];if(r.keys.length===this.pressedKeys.size&&r.keys.every(e=>bn.has(e)?this.pressedKeys.has(e):!1)){this.triggerKeybind(r,n,t);return}}for(let[t,n]of this.preferencesKeybindToCallbacks.entries()){let r=e[t];r.keys.every(e=>bn.has(e)?this.pressedKeys.has(e):(this.logger.error(`Unknown key`,e,r),!1))&&this.triggerKeybind(r,n,t)}}triggerKeybind(e,t,n){let r=e.mode;if(r===`toggle`&&t.toggle&&t.toggle.length>0&&!this.triggeredToggleKeybinds.has(n)){let r;for(let e of t.toggle){let t=e();typeof t==`string`&&r===void 0&&(r=t)}this.triggeredToggleKeybinds.add(n),this.logger.log(r?`Keybind pressed rejected: ${r}`:`Keybind pressed accepted`,this.getKeybindToString(e))}if(r===`hold`&&t.down&&t.down.length>0&&!this.activeKeybinds.has(n)){let r;for(let e of t.down){let t=e();if(typeof t==`string`){r=t;break}}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 Cn(e){let t=new Sn(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 Y(){return W.getInstance().getInterface(`OGG_SIEGE`)}function wn(){let e=K.getInstance(),t=P.getInstance(),n=G.getInstance();n.meta=X(),e.on([`gameReady`,`gameClose`],()=>{n.meta||=X(),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 X(){return{app_id:global.OVERLAYED.APPLICATION_ID,user_id:rn(),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 Tn(){function e(e,t){return e.once(`closed`,()=>{e.isDestroyed()||G.getInstance().track(`window_closed`,{url:e.webContents.getURL(),in_game:t})}),e.on(`unresponsive`,()=>{e.isDestroyed()||G.getInstance().track(`window_unresponsive`,{url:e.webContents.getURL(),in_game:t})}),G.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(Y().instance.newWindowInternal(global.OVERLAYED.electron.BrowserWindow,t),!0),on:(e,t)=>Y().instance.on(e,t),off:(e,t)=>Y().instance.off(e,t),once:(e,t)=>Y().instance.once(e,t),addListener:(e,t)=>Y().instance.addListener(e,t),removeListener:(e,t)=>Y().instance.removeListener(e,t),removeAllListeners:()=>Y().instance.removeAllListeners(),prependListener:(e,t)=>Y().instance.prependListener(e,t),prependOnceListener:(e,t)=>Y().instance.prependOnceListener(e,t),getActiveGameInfo:()=>{let e=Y(),t=ut.getInstance();return{resolution:e.resolution,isConnected:t.hasConnection}}}}const En=N(class extends xt{renderInterface;globalCursorOverrideCount=new Set;globalMouseBlockCount=new Set;globalKeyboardBlockCount=new Set;keyInputBlocks={};constructor(e){super(`OverridesManager`),this.renderInterface=W.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)}},`OGG_SIEGE`);function Dn(){return{scope:e=>En.getInstance().scope(e),raw:{setGlobalMouseBlock:e=>Y().instance.setGlobalMouseBlock(e),setGlobalKeyboardBlock:e=>Y().instance.setGlobalKeyboardBlock(e),setGlobalCursorOverride:e=>Y().instance.setGlobalCursorOverride(e),setKeyInputBlock:(e,t)=>Y().instance.setKeyInputBlock(e,t),getGlobalMouseBlock:()=>Y().instance.getGlobalMouseBlock(),getGlobalKeyboardBlock:()=>Y().instance.getGlobalKeyboardBlock(),getGlobalCursorOverride:()=>Y().instance.getGlobalCursorOverride(),getKeyInputBlock:e=>Y().instance.getKeyInputBlock(e)}}}function On(){return{track:(e,t)=>{G.getInstance().track(`custom__${String(e)}`,t)}}}var kn=_e(((e,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`)for(let t of Object.values({KEYDOWN:256,LBUTTONUP:514,MBUTTONUP:520,RBUTTONUP:517,XBUTTONUP:524,TOUCH:576}))e.hookWindowMessage(t,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}}))();function An(){return{registerWindow:e=>{(0,kn.setupRevUtils)(e,global.OVERLAYED.electron)}}}function jn(e){let t=Ye(global.OVERLAYED.APPLICATION_ID),n=$e(t,{recursive:!0}),r=qe(),i=$e(r,{recursive:!0});L.getInstance().info(`Logs path: `,t),L.getInstance().info(`Overlayed logs path: `,r);let a=new fe;return[...n,...i].forEach(([e,t])=>{L.getInstance().info(`Zipping: `,t);let n=oe(t),r=ee(t);a.file(r,n,{compression:`DEFLATE`})}),Object.entries(e?.additionalFiles??{}).forEach(([e,t])=>{L.getInstance().info(`Zipping extra file: `,e),a.file(e,t,{compression:`DEFLATE`})}),a}async function Mn(e,t,n){let r={...t,category:e,version:`${global.OVERLAYED.APP_VERSION}@${global.OVERLAYED.APP_BUILD_CHANNEL}`,log_zip:`data:application/zip;base64,${n}`},{app_version:i,app_channel:a,user_id:o}=X();try{let e=await fetch(`https://api.stats.cc/v1/overlay/contact`,{method:`POST`,body:JSON.stringify(r),redirect:`follow`,headers:{"Content-Type":`application/json`}});if(!e.ok){L.getInstance().error(`OLD - Failed to submit feedback`,await e.json());return}}catch(e){L.getInstance().error(`OLD - Failed to submit feedback`,e);return}return Pt(global.OVERLAYED.APPLICATION_ID,{file:Buffer.from(n,`base64`),data:{app_version:i,app_channel:a,type:e,cortex_user_id:o,...t}}).then(e=>(L.getInstance().info(`Feedback submitted`,e),e.data.id)).catch(e=>{console.error(JSON.stringify(e,null,2)),L.getInstance().error(`Failed to submit feedback`,e)})}function Nn(e){let t=new Ze(`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),submitFeedback:async(e,t,n)=>(G.getInstance().track(e===`bug_report`?`bug_report_submitted`:`suggestion_submitted`,{version:global.OVERLAYED.APP_VERSION,channel:global.OVERLAYED.APP_BUILD_CHANNEL}),await Mn(e,t,await jn(n).generateAsync({type:`base64`})))}}const Pn=1e3;function Fn(e,t,n,i,a){let o=ut.getInstance(),s=L.getInstance().scope(`SetupPipeServer`);s.log(`Initializing`);function c(e,t){let r=n.get(t);if(!r)n.set(t,[e]);else{if(r.length>=Pn){P.getInstance().warn(`Event buffer full, removing oldest event`,`EVENT_BUFFER_FULL`,{summary:`Event buffer overflow for module ${t}. Buffer size: ${r.length}, max: ${Pn}`});return}r.push(e)}}function l(n){s.info(n);let i=tn(n);if(i instanceof r.errors){G.getInstance().track(`invalid_game_event`,{}),P.getInstance().warn(`Invalid event`,`INVALID_EVENT`,{summary:i.summary});return}let o=yt.includes(i.type),l=e.modules.find(e=>e.key===`universal`),u=o?l:e.modules.find(e=>e.key===i.game);if(!u){s.warn(`Invalid module`,{module:o?`universal`:i.game});return}let d=u.events.event,f=d(n);if(f instanceof r.errors){if(`type`in f.byPath)return;s.warn(`Invalid event`,{summary:f.summary}),G.getInstance().track(`invalid_game_event`,{game:i.game,type:i.type,summary:f.summary}),P.getInstance().warn(`Invalid event`,`INVALID_EVENT`,{summary:f.summary});return}if(!a[u.key]){c(f,u.key);return}if(f.type===`unsupported_game_version`){let{content:e}=f;G.getInstance().track(`unsupported_game_version`,{game:f.game,hash:e.process_hash,version:e.game_version})}let p=q(u.key,f.type),m=q(u.key,`*`),ee=t.get(p),te=t.get(m),h=[...Array.from(ee??[]),...Array.from(te??[])];if(h.length===0){s.info(`No handlers found for event`,{event:f});return}h.forEach(e=>{e(f)})}return i.on(`flushEvents`,e=>{if(a[e])return;a[e]=!0;let t=n.get(e);t&&(L.getInstance().info(`Flushing ${t.length} events for module ${e}`),t.forEach(e=>l(e)),n.delete(e))}),o.on(`data`,e=>e.forEach(l)),o.on(`error`,e=>{s.error(`Pipe server error`,e),P.getInstance().error(`Pipe server error`,`PIPE_SERVER_ERROR`,{error:e})}),o}const In=r({dismissedNotices:ve(r.string).array()}),Ln=N(class extends z{NOTICE_FETCH_INTERVAL=1e3*60*5;MAX_DISMISSED_NOTICES=100;_noticeFetchInterval=null;_notices=[];_noticesFile;_boundOnGameReady=this.onGameReady.bind(this);get notices(){let e=this._noticesFile.get().dismissedNotices;return this._notices.filter(t=>!e.includes(t.id))}constructor(){super(`NoticeManager`),this._noticesFile=this.getNoticesFile(),this._noticesFile.load(),this.fetchNotices(),this.setupNoticeInterval(),K.getInstance().on(`gameReady`,this._boundOnGameReady)}destroy(){this._noticeFetchInterval&&=(clearInterval(this._noticeFetchInterval),null),K.getInstance().off(`gameReady`,this._boundOnGameReady),super.destroy()}dismissNotice(e){let t=this._notices.find(t=>t.id===e);if(!t||!t.dismissible)return;let n=this._noticesFile.get().dismissedNotices;n.unshift(e),this._noticesFile.set({dismissedNotices:n.slice(0,this.MAX_DISMISSED_NOTICES)}),this.emitNoticesUpdated()}onGameReady(){this.fetchNotices()}setupNoticeInterval(){this._noticeFetchInterval=setInterval(()=>{this.fetchNotices()},this.NOTICE_FETCH_INTERVAL)}getNoticesFile(){return new F({path:en([`notices.json`]),schema:In,default:{dismissedNotices:[]}})}async fetchNotices(){let e=K.getInstance().getActiveGames();try{let{data:t}=await Ft(global.OVERLAYED.APPLICATION_ID,{channel:global.OVERLAYED.APP_BUILD_CHANNEL,version:global.OVERLAYED.APP_VERSION,games:e});this._notices=t,this.emitNoticesUpdated()}catch(e){this.logger.error(`Failed to fetch notices`,e)}}emitNoticesUpdated(){this.emit(`noticesUpdated`,{notices:this.notices})}});function Rn(){let e=Ln.getInstance();return{on:(t,n)=>{e.on(t,n)},off:(t,n)=>{e.off(t,n)},dismissNotice:t=>{e.dismissNotice(t)},getNotices:()=>e.notices}}let Z=!1,zn={},Q,Bn=new M,$;function Vn(e){Un(e);let t=Hn(e),{init:n=!0,debug:r=!1,silent:i=!0}=t;if(Wn(e),L.getInstance().init(e.applicationId,r,i),Z)return Q;function a(){if(Z){L.getInstance().warn(`Overlayed already initialized`);return}wn();let e=new Map,n=new Map,r=_n(t.modules,e,Bn),i=vn(),o=Cn(t.keybinds),s=Tn(),c=Dn(),l=An(),u=On(),d=Nn(t),f=Rn();L.getInstance().log(`Overlayed initialized`),Gn(t),Fn(t,e,n,Bn,zn),Z=!0,Q={...r,...i,ads:l,keybinds:o,windows:s,input:c,cortex:u,hasAnyActiveProcesses:()=>U.getInstance().hasAnyActiveProcesses,hasAnyActiveGames:()=>K.getInstance().isInGame,init:a,log:d,initialized:Z,notices:f},Q.universal.on(`logged_in`,e=>{G.getInstance().track(`account_id`,{account_id:e.content.account_id,game:e.game})})}return n?(a(),Q):new Proxy({init:a},{get:(e,t)=>{if(t!==`init`&&!Z)throw Error(`overlayed was called before initialized: ${t}`);return t===`init`?e[t]:Q[t]}})}function Hn(e){return{...e,modules:[...e.modules,bt()]}}global.OVERLAYED=new Proxy({},{get:()=>{throw Error(`function overlayed was not called`)}});function Un(e){if(!ye(e.applicationId))throw Error(`Invalid applicationId, must be a valid ULID.`)}function Wn(e){global.OVERLAYED={APPLICATION_ID:Mt(e.applicationId),APP_BUILD_CHANNEL:e.channel??`alpha`,APP_VERSION:e.version??`0.0.0`,PACKAGE_VERSION:`0.34.7`,FRONTEND_VERSION:`0.0.0`,sessionId:an(),electron:e.electron},Dt(()=>({package_version:global.OVERLAYED.PACKAGE_VERSION}))}function Gn(e){let t=e.universal?[`*`]:e.modules.map(e=>e.key);K.getInstance().setSubscribedGames(t),gn.getInstance().init(),K.getInstance().init(),U.getInstance().init(),H.getInstance().init();async function n(){let e=Nt(global.OVERLAYED.APPLICATION_ID).then(e=>e.data),t=rn();L.getInstance().log(`userId`,t);let n={...await e,userId:t};return L.getInstance().log(`appInfo`,n),n}let r;global.OVERLAYED.electron.ipcMain.handle(`getAppInfo`,async()=>(r??=n(),r)),G.getInstance().track(`start`,{});try{$&&clearInterval($),$=setInterval(()=>{try{on()}catch{}},3e4),$.unref()}catch(e){L.getInstance().log(`failed to start sessionLastUsed interval`,e)}async function i(){let e={};e.os=g.platform().trim(),e.os_version=process.getSystemVersion().trim(),e.architecture=g.arch().trim();let t=g.cpus();t.length>0?(e.cpu=t[0].model.trim(),e.cpu_cores=t.length,e.cpu_speed=t[0].speed):L.getInstance().warn(`Failed to collect CPU info`);let n=await ge.graphics();L.getInstance().info(`GPU info`,n);let r=n.controllers.sort((e,t)=>(t.vram??0)-(e.vram??0))[0];r?(e.gpu=r.model.trim(),e.gpu_memory=r.vram??0):L.getInstance().warn(`Failed to find primary GPU`),e.display_count=n.displays.length;let i=n.displays.find(e=>e.main)??n.displays[0];i?(e.primary_display_resolution_x=i.resolutionX??void 0,e.primary_display_resolution_y=i.resolutionY??void 0,e.primary_display_refresh_rate=i.currentRefreshRate??void 0):L.getInstance().warn(`Failed to find main display`),e.ram=process.getSystemMemoryInfo().total;let a=g.homedir(),o=await he.statfs(a);return o&&`blocks`in o&&`bsize`in o&&`bavail`in o?(e.disk=o.blocks*o.bsize,e.disk_free=o.bavail*o.bsize):L.getInstance().warn(`Failed to collect disk info`),L.getInstance().log(`Retrieved system information`,e),e}me.on(`ready`,()=>{i().then(e=>{G.getInstance().track(`system_info`,e)}).catch(e=>{L.getInstance().log(`Failed to retrieve system information`,e)})}),me.on(`quit`,()=>{G.getInstance().track(`electron_quit`,{}),Kn()}),process.on(`exit`,()=>{G.getInstance().track(`exit`,{}),Kn()})}async function Kn(){try{on()}catch{}try{$&&clearInterval($),$=void 0}catch{}await G.getInstance().flush(),H.getInstance().destroy(),K.getInstance().destroy(),gn.getInstance().destroy(),U.getInstance().destroy(),W.getInstance().getInterface(`OGG_SIEGE`).destroy(),ut.getInstance().destroy(),P.getInstance().destroy()}export{dt as RenderInterface,pt as VirtualKey,nt as defineConfig,Vn as overlayed,ln as setFetchLatestTokenCallback,Tt as setUpdaterTokenResolver};
1
+ import{createRequire as e}from"node:module";import{Type as t,scope as n,type as r}from"arktype";import i from"mitt";import a,{createWriteStream as o,existsSync as s,mkdirSync as c,readdirSync as l,unlinkSync as u,writeFileSync as d}from"fs";import{ensureFileSync as f}from"fs-extra";import{join as p}from"path";import m,{basename as h,resolve as g}from"node:path";import _ from"events";import{copyFileSync as ee,createReadStream as te,existsSync as v,mkdirSync as ne,readFileSync as re,readdirSync as ie,writeFileSync as ae}from"node:fs";import"glob";import"jiti";import oe from"xior";import y from"fs/promises";import b from"jszip";import{createHash as se}from"node:crypto";import{app as x}from"electron";import*as S from"node:os";import*as ce from"node:fs/promises";import le from"systeminformation";var ue=Object.create,de=Object.defineProperty,fe=Object.getOwnPropertyDescriptor,pe=Object.getOwnPropertyNames,me=Object.getPrototypeOf,he=Object.prototype.hasOwnProperty,ge=(e,t)=>()=>(t||e((t={exports:{}}).exports,t),t.exports),_e=(e,t,n,r)=>{if(t&&typeof t==`object`||typeof t==`function`)for(var i=pe(t),a=0,o=i.length,s;a<o;a++)s=i[a],!he.call(e,s)&&s!==n&&de(e,s,{get:(e=>t[e]).bind(null,s),enumerable:!(r=fe(t,s))||r.enumerable});return e},ve=(e,t,n)=>(n=e==null?{}:ue(me(e)),_e(t||!e||!e.__esModule?de(n,`default`,{value:e,enumerable:!0}):n,e));function ye(e){return e}function C(e){return e?Array.isArray(e)?e:[e]:[]}function be(e){return typeof e==`string`&&/^01[0-9A-HJKMNP-TV-Z]{24}$/.test(e)}var xe=class{data=[];constructor(){}get size(){return this.data.length}add(e){this.data.push(e)}next(){return this.data.shift()}clear(){this.data.length=0}*flush(){for(;this.size>0;){let e=this.next();e&&(yield e)}}},w=ve(ge(((e,t)=>{let n=process||{},r=n.argv||[],i=n.env||{},a=!(i.NO_COLOR||r.includes(`--no-color`))&&(!!i.FORCE_COLOR||r.includes(`--color`)||n.platform===`win32`||(n.stdout||{}).isTTY&&i.TERM!==`dumb`||!!i.CI),o=(e,t,n=e)=>r=>{let i=``+r,a=i.indexOf(t,e.length);return~a?e+s(i,t,n,a)+t:e+i+t},s=(e,t,n,r)=>{let i=``,a=0;do i+=e.substring(a,r)+n,a=r+t.length,r=e.indexOf(t,a);while(~r);return i+e.substring(a)},c=(e=a)=>{let t=e?o:()=>String;return{isColorSupported:e,reset:t(`\x1B[0m`,`\x1B[0m`),bold:t(`\x1B[1m`,`\x1B[22m`,`\x1B[22m\x1B[1m`),dim:t(`\x1B[2m`,`\x1B[22m`,`\x1B[22m\x1B[2m`),italic:t(`\x1B[3m`,`\x1B[23m`),underline:t(`\x1B[4m`,`\x1B[24m`),inverse:t(`\x1B[7m`,`\x1B[27m`),hidden:t(`\x1B[8m`,`\x1B[28m`),strikethrough:t(`\x1B[9m`,`\x1B[29m`),black:t(`\x1B[30m`,`\x1B[39m`),red:t(`\x1B[31m`,`\x1B[39m`),green:t(`\x1B[32m`,`\x1B[39m`),yellow:t(`\x1B[33m`,`\x1B[39m`),blue:t(`\x1B[34m`,`\x1B[39m`),magenta:t(`\x1B[35m`,`\x1B[39m`),cyan:t(`\x1B[36m`,`\x1B[39m`),white:t(`\x1B[37m`,`\x1B[39m`),gray:t(`\x1B[90m`,`\x1B[39m`),bgBlack:t(`\x1B[40m`,`\x1B[49m`),bgRed:t(`\x1B[41m`,`\x1B[49m`),bgGreen:t(`\x1B[42m`,`\x1B[49m`),bgYellow:t(`\x1B[43m`,`\x1B[49m`),bgBlue:t(`\x1B[44m`,`\x1B[49m`),bgMagenta:t(`\x1B[45m`,`\x1B[49m`),bgCyan:t(`\x1B[46m`,`\x1B[49m`),bgWhite:t(`\x1B[47m`,`\x1B[49m`),blackBright:t(`\x1B[90m`,`\x1B[39m`),redBright:t(`\x1B[91m`,`\x1B[39m`),greenBright:t(`\x1B[92m`,`\x1B[39m`),yellowBright:t(`\x1B[93m`,`\x1B[39m`),blueBright:t(`\x1B[94m`,`\x1B[39m`),magentaBright:t(`\x1B[95m`,`\x1B[39m`),cyanBright:t(`\x1B[96m`,`\x1B[39m`),whiteBright:t(`\x1B[97m`,`\x1B[39m`),bgBlackBright:t(`\x1B[100m`,`\x1B[49m`),bgRedBright:t(`\x1B[101m`,`\x1B[49m`),bgGreenBright:t(`\x1B[102m`,`\x1B[49m`),bgYellowBright:t(`\x1B[103m`,`\x1B[49m`),bgBlueBright:t(`\x1B[104m`,`\x1B[49m`),bgMagentaBright:t(`\x1B[105m`,`\x1B[49m`),bgCyanBright:t(`\x1B[106m`,`\x1B[49m`),bgWhiteBright:t(`\x1B[107m`,`\x1B[49m`)}};t.exports=c(),t.exports.createColors=c}))(),1),T=class{emitter;constructor(){this.emitter=i()}on(e,t){C(e).forEach(e=>{this.emitter.on(e,t)})}off(e,t){C(e).forEach(e=>{this.emitter.off(e,t)})}emit(e,t){C(e).forEach(e=>{this.emitter.emit(e,t)})}removeAllListeners(){this.emitter.all.clear()}},Se=class{listeners;constructor(){this.listeners=new Map}on(e,t){C(e).forEach(e=>{let n=this.listeners.get(e)||new Set;n.add(t),this.listeners.set(e,n)})}off(e,t){C(e).forEach(e=>{let n=this.listeners.get(e);n&&n.delete(t)})}async emit(e,...t){let n=C(e).flatMap(e=>{let t=this.listeners.get(e)||new Set,n=this.listeners.get(`*`)||new Set;return[...Array.from(t),...Array.from(n)]});return n.length===0?[]: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}}))}removeAllListeners(){this.listeners.clear()}};function E(e,...t){return class extends e{static _instance;static getInstance(){return this._instance||=new e(...t),this._instance}static clearInstance(){this._instance=void 0}}}const D=E(class extends T{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()})}});var O=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){return this.get()[e]}save(e){let t=this.onBeforeSave(e);try{f(this.getFilePath()),a.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=a.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=r(`string.json.parse`).to(`object`)(e);if(t instanceof r.errors)return this._defaultValue;let n=this._schema[`~standard`].validate(t);if(n instanceof Promise)throw Error(`StructuredConfigFile does not support async validation`);return n.issues?this.migrate(t,this._defaultValue):this.migrate(n.value,this._defaultValue)}catch{return this._defaultValue}}canReadWriteFile(e){try{return a.accessSync(e,a.constants.R_OK|a.constants.W_OK),!0}catch{return!1}}fileExists(e){try{return a.accessSync(e,a.constants.F_OK),!0}catch{return!1}}migrate(e,t){let n={...e};for(let r in t)Object.prototype.hasOwnProperty.call(t,r)&&(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){D.getInstance().error(`Invalid config file`,`INVALID_CONFIG_FILE`,{issues:e.map(e=>e.message),filePath:this._path,data:this.data})}};function Ce(e,t,n){return typeof e!=`object`||!e?String(e):e instanceof Error?JSON.stringify(e,Object.getOwnPropertyNames(e),n):e instanceof Map?JSON.stringify(Object.fromEntries(e.entries()),t,n):e instanceof Set?JSON.stringify(Array.from(e),t,n):JSON.stringify(e,t,n)}var we=class e extends T{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(`info`,...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;return{timestamp:n.toISOString().replace(`T`,` `).replace(/\.\d+Z$/,``)+`.${n.getUTCMilliseconds().toString().padStart(3,`0`)}`,level:e,message:t.map(e=>Ce(e)).join(` `)}}getFileName(e){return`${this.baseFileName}-${e}.log`}ensureLogDirectory(){try{c(this.logPath,{recursive:!0})}catch(e){throw console.error(`Failed to create log directory ${this.logPath}:`,e),e}}ensureLogFile(){let e=p(this.logPath,this.getFileName(this.currentDate));if(!s(e))try{d(e,``,`utf8`)}catch(t){throw console.error(`Failed to create log file ${e}:`,t),t}}getDateString(e){return`${e.getUTCFullYear()}-${(e.getUTCMonth()+1).toString().padStart(2,`0`)}-${e.getUTCDate().toString().padStart(2,`0`)}`}createStream(){return o(p(this.logPath,this.getFileName(this.currentDate)),{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=l(this.logPath),t=new Date,n=new Date(Date.UTC(t.getUTCFullYear(),t.getUTCMonth(),t.getUTCDate()-7));e.filter(e=>e.startsWith(this.baseFileName)&&e.endsWith(`.log`)).filter(e=>{let[t,r,i]=e.replace(`${this.baseFileName}-`,``).replace(`.log`,``).split(`-`).map(Number);return new Date(Date.UTC(t,r-1,i))<=n}).forEach(e=>{try{u(p(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 k=()=>m.join(process.env.APPDATA??``,`overlayed`),Te=()=>m.join(k(),`logs`),Ee=e=>m.join(k(),`apps`,e),De=e=>m.join(Ee(e),`logs`),Oe=()=>m.join(k(),`meta.json`);var ke=class{fileLogger;path;appId;messageQueue=new xe;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=De(e),this.fileLogger=new we(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=w.default.cyan(`[${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:w.default.red,warn:w.default.yellow,debug:w.default.blue,log:w.default.white};if(this.silent&&!this._debug)return;let{timestamp:r,message:i}=we.getMessageElements(e,...t),a=console[e],o=n[e];a(`${w.default.gray(r)} ${o(i)}`)}};const A=E(ke,`overlayed.log`);var Ae=class extends _{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=new Map,i=new Set,a=new Set,o=[];for(let e=0;e<n;e++)o.push(e);let s=async n=>{let s=n*t,c=Math.min(s+t,this.blob.size),l=this.blob.slice(s,c);try{await e(l,n),a.add(n),this.emit(`chunkComplete`,n),i.delete(n)}catch(e){let t=r.get(n)||0;t<5?(r.set(n,t+1),await new Promise(e=>setTimeout(e,(t+1)*1e3)),o.push(n)):(a.add(n),this.emit(`error`,e),this.shouldStop=!0,i.delete(n))}},c=[],l=async()=>{for(;(o.length>0||i.size>0)&&!this.shouldStop;){if(o.length===0){await new Promise(e=>setTimeout(e,10));continue}let e=o.shift();a.has(e)||i.has(e)||(i.add(e),await s(e))}};for(let e=0;e<this.maxConcurrent;e++)c.push(l());await Promise.all(c)}};function je(e,t){let{recursive:n}=Me(t);return v(e)?n?Ne(e).map(t=>[e,t]):ie(e).map(t=>[e,t]):[]}function Me(e){return{recursive:e?.recursive??!0}}function Ne(e){return ie(e,{withFileTypes:!0}).flatMap(t=>{let n=m.join(e,t.name);return t.isDirectory()?Ne(n):[n]})}function Pe(e){return Fe(e),e}function Fe(e){if(!be(e.applicationId))throw Error(`Invalid applicationId, must be a valid ULID.`)}const{PipeEventServer:Ie,PipeEventClient:Le,PipeEventBase:Re,ProcessMonitor:ze,Process:Be,HardwareInterface:Ve}=e(import.meta.url)(`@overlayed/app/dist/native-interface/build/overlayed_native_interface_x64.node`),j=E(class extends T{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(),null)}init(){this.server=new Ie(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.emit(`connected`,void 0)}),this.server.on(`disconnected`,()=>{this._hasConnection=!1,this.emit(`disconnected`,void 0)})}},`overlayed-event-server`),{RenderInterface:He,renderHookPath:Ue}=e(import.meta.url)(`@overlayed/app/dist/render-interface/build/overlayed_render_interface_x64.node`);let We=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}({});const M=r({game:`string`,type:`string`,creation_time:`number`}).and({game:`'siege' | 'tft'`}),Ge=M.and({type:`'logged_in'`,content:{account_id:`string`}}),Ke=M.and({type:`'module_loaded'`,content:{game_version:`string`,process_hash:`string`}}),qe=M.and({type:`'module_unloaded'`}),Je=M.and({type:`'unsupported_game_version'`,content:{game_version:`string`,process_hash:`string`}}),Ye=n({"#event1":`logged_in | module_loaded | module_unloaded | unsupported_game_version`,event:`event1`,logged_in:Ge,module_loaded:Ke,module_unloaded:qe,unsupported_game_version:Je}).export(),Xe=Object.keys(Ye).filter(e=>e!==`event`);function Ze(){return{key:`universal`,events:Ye}}var Qe=class{logger;initialized=!1;constructor(e){this.logger=A.getInstance().scope(e)}init(){this.logger.log(`Initializing`),this.initialized=!0}destroy(){this.logger.log(`Destroying`),this.initialized=!1}},N=class extends T{logger;initialized=!1;constructor(e){super(),this.logger=A.getInstance().scope(e)}init(){this.logger.log(`Initializing`),this.initialized=!0}destroy(){this.logger.log(`Destroying`),this.initialized=!1,this.removeAllListeners()}},$e=class extends Se{logger;initialized=!1;constructor(e){super(),this.logger=A.getInstance().scope(e)}init(){this.logger.log(`Initializing`),this.initialized=!0}destroy(){this.logger.log(`Destroying`),this.initialized=!1,this.removeAllListeners()}};const et=oe.create({baseURL:`https://updater.stats.cc`,headers:{Accept:`application/json`,"Accept-Encoding":`gzip, deflate, br`}});let tt;function nt(e){tt=e}et.interceptors.request.use(e=>{let t=tt?.();return t?(e.headers??={},e.headers.Authorization=t,e):e});const P=oe.create({baseURL:`https://api.overlayed.gg`,headers:{Accept:`application/json`,"Accept-Encoding":`gzip, deflate, br`}});let rt;function it(e){rt=e}function at(e){return`overlayed/app (${Object.entries(e).map(([e,t])=>`${e}=${t}`).join(`; `)})`}P.interceptors.request.use(e=>{e.headers??={};let t=rt?.();return t&&(e.headers[`User-Agent`]=at(t)),e});function ot(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 st(e){return e}function ct(e){return e?t=>(e(t),t):st}const lt=ct();function ut(e){return P.get(`/v1/public/applications/${e}`)}function dt(e,t){let n=new FormData;return n.append(`file`,new Blob([t.file],{type:`application/zip`}),`logs.zip`),n.append(`data`,JSON.stringify(t.data)),P.post(`/v1/public/applications/${e}/feedbacks`,n)}function ft(e,t){return P.get(`/v1/public/applications/${e}/notices`,{params:t})}function pt(e,t){return P.get(`/v1/public/modules/${e}/release`,{params:{cortex_user_id:t}})}function mt(e,t,n){return P.post(`/v1/public/modules/${e}/releases/${t}/download`,{download_token:n})}async function ht(e,t){if(e.method!==`GET`)throw Error(`Unsupported presigned request method: ${e.method}`);let n=await fetch(e.url,{method:e.method,headers:e.headers,signal:t?.signal});if(!n.ok){let e=await gt(n);throw Error(`Presigned download failed (${n.status} ${n.statusText})${e?`: ${e}`:``}`)}let r=await n.arrayBuffer();return new Uint8Array(r)}async function gt(e){try{let t=(await e.text()).trim();if(t.length===0)return;let n=2048;return t.length>n?`${t.slice(0,n)}…`:t}catch{return}}function _t(){return P.get(`/v1/public/raven/config`)}function vt(e,t){return P.get(`/v1/public/raven/games/${e}/builds/${t}`)}function yt(e,t){return P.post(`/v1/public/raven/games/${e}/builds/upload`,null,{params:t})}function bt(e,t){let n=new FormData;return n.append(`file`,t.chunk),P.patch(`/v1/public/raven/games/${e}/builds/upload`,n,{params:t})}function xt(e){let t=Date.now(),n=ot(e.messages.map(e=>St(t,e)),250),r=Promise.all(n.map(async t=>P.post(`/v1/public/cortex/events`,{...e,messages:t})));return r.catch(e=>{let t=e?.response?.data||e?.message||e;console.error(`Failed to submit cortex events`,t)}),r}function St(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 Ct(e){return e instanceof Error&&(e.name===`XiorError`||e.name===`XiorTimeoutError`)}function wt(e){return!!(e&&`kind`in e.data&&`message`in e.data)}const{PipeEventServer:Tt,PipeEventClient:Et,PipeEventBase:Dt,ProcessMonitor:Ot,Process:kt,HardwareInterface:At}=e(import.meta.url)(`@overlayed/app/dist/native-interface/build/overlayed_native_interface_x64.node`);function F(e=[]){return m.normalize(m.join(Ee(global.OVERLAYED.APPLICATION_ID),...e))}const jt=r({game:`string`,type:`string`,creation_time:`number`}),I=new O({path:Oe(),schema:r({userId:`string | undefined`,sessionId:`string | undefined`,sessionLastUsed:`number | undefined`,"debug?":{"ri_disabled?":`boolean`,"gm_disabled?":`boolean`}}),default:{userId:void 0,sessionId:void 0,sessionLastUsed:void 0}});function Mt(){let{debug:e}=I.get();return e?{ri_disabled:e.ri_disabled??!1,gm_disabled:e.gm_disabled??!1}:{ri_disabled:!1,gm_disabled:!1}}function L(){let e=I.get().userId;if(e)return e;let t=Ft();return I.set({...I.get(),userId:t}),t}function Nt(){let e=I.get();if(e.sessionId&&typeof e.sessionLastUsed==`number`&&Date.now()-e.sessionLastUsed<=300*1e3)return e.sessionId;let t=crypto.randomUUID();return I.set({...e,sessionId:t,sessionLastUsed:Date.now()}),t}function Pt(){try{let e=I.get();I.set({...e,sessionLastUsed:Date.now()})}catch(e){A.getInstance().log(`Failed to update sessionLastUsed`,e)}}function Ft(){try{return At.generateUniqueIdentifier()}catch{return crypto.randomUUID()}}let It;function Lt(e){It=e}const R=E(class extends N{UPDATE_CHECK_INTERVAL_MS=1e3*60*5;targetDir;updateInterval;constructor(){super(`NativeModuleManager`),this.targetDir=m.join(k(),`resources`),this.logger.log(`Target directory`,this.targetDir)}async initWithDlls(e){super.init(),await y.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),void 0),super.destroy()}async getDllFile(e){let t=await this.getCurrentBuildInfo(e);if(!t){this.logger.error(`No build found for module`,{moduleId:e});return}let n=this.getBuildPath(e,t.buildId);if(!v(n)){this.logger.error(`No build file found for module`,{moduleId:e});return}let r=m.join(n,t.buildFileName);if(!v(r)){this.logger.error(`No DLL file found for module`,{moduleId:e});return}return r}async getCurrentBuildInfo(e){try{let t=m.join(this.targetDir,e,`build.json`),n=await y.readFile(t,`utf-8`);return JSON.parse(n)}catch{return null}}getModulePath(e){return m.join(this.targetDir,e)}getBuildPath(e,t){return m.join(this.getModulePath(e),t)}async checkForUpdates(e){this.logger.log(`Checking for updates`);let t=L();if(!t){this.logger.error(`Failed to resolve cortex user id`);return}this.logger.log(`Cortex User ID`,t),await It?.();for(let n of e)try{let{data:e}=await pt(n,t);this.logger.log(`Release`,e);let r=(await this.getCurrentBuildInfo(n))?.buildId||null;this.logger.log(`${n} > Performing update check. current: ${r}, requested: ${e.build_id}`),e.build_id!==r||await this.isDownloadCorrupted(this.getBuildPath(n,e.build_id),e)?(this.logger.log(`${n} > Update found. current: ${r}, requested: ${e.build_id}`),this.logger.log(`${n} > Downloading and extracting DLLs`),await this.downloadAndExtractDll(n,e),this.logger.log(`${n} > Cleaning up other builds`),await this.cleanupExistingBuilds(n,e.build_id),this.emit(`dllUpdated`,{moduleId:n,buildId:e.build_id,releaseId:e.release_id})):this.logger.log(`${n} > No update found`)}catch(e){this.logger.error(`${n} > Error checking/updating`,e)}}async downloadAndExtractDll(e,t){this.logger.log(`${e} > Requesting download for build ${t.build_id}`);let{data:n}=await mt(e,t.release_id,t.download_token);this.logger.log(`${e} > Downloading DLLs for build ${t.build_id}`);let r=await ht(n,{signal:AbortSignal.timeout(1e3*60*5)});this.logger.log(`${e} > Downloaded zip file for build ${t.build_id}`);let i=this.getBuildPath(e,t.build_id);await y.mkdir(i,{recursive:!0});let a=new b;await a.loadAsync(r);let o=Object.keys(a.files).map(e=>({name:e,file:a.files[e]})).filter(({file:e})=>!e.dir);if(o.length!==1){this.logger.error(`${e} > Zip must contain exactly 1 file, got ${o.length}`);return}let s=o[0],c=m.basename(s.name),l=m.normalize(c),u=m.isAbsolute(l),d=l.startsWith(`..`)||l.includes(`..${m.sep}`);if(c===``||c===`.`||c===`..`){this.logger.error(`${e} > Zip contained an invalid file name: ${s.name}`);return}if(!c.toLowerCase().endsWith(`.dll`)){this.logger.error(`${e} > Zip contained a non-dll file: ${s.name}`);return}if(u||d){this.logger.error(`${e} > Zip entry path is unsafe: ${s.name}`);return}let f=m.join(i,l),p=await s.file.async(`nodebuffer`);await y.writeFile(f,p),this.logger.log(`${e} > Extracted 1 file to ${f}`);let h={buildId:t.build_id,buildFileName:t.build_file_name},g=m.join(this.getModulePath(e),`build.json`);await y.writeFile(g,JSON.stringify(h),`utf-8`),this.logger.log(`${e} > Saved buildId to file: ${t.build_id}`)}async cleanupExistingBuilds(e,t){let n=this.getModulePath(e),r=this.getBuildPath(e,t),i=await y.readdir(n,{withFileTypes:!0});for(let t of i)t.isDirectory()&&m.join(n,t.name)!==r&&(await y.rm(m.join(n,t.name),{recursive:!0,force:!0}),this.logger.log(`${e} > Cleaned up build: ${t.name}`))}async hasPathAccess(e){try{return await y.access(e,y.constants.F_OK),!0}catch{return!1}}async isDownloadCorrupted(e,t){if(!await this.hasPathAccess(e))return this.logger.error(`Download is corrupted. Path does not exist: ${e}`),!0;let n=t.build_file_name,r=m.join(e,n);if(!v(r))return this.logger.error(`Download is corrupted. Build file not found: ${r}`),!0;let i=await y.readFile(r),a=se(`sha256`).update(i).digest(`hex`);return a.toLowerCase()===t.build_hash.toLowerCase()?!1:(this.logger.error(`Download is corrupted. Build file hash mismatch: ${n} ${a.toLowerCase()} !== ${t.build_hash.toLowerCase()}`),!0)}}),z=E(class extends N{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),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),R.getInstance().destroy(),super.destroy()}async fetchRavenConfig(){try{this._ravenConfig={games:(await _t()).data.games},this.resetState();let e=new Set;for(let t of this._ravenConfig.games){for(let e of t.executables){let n=e.toLowerCase();this._executableToGameMap.set(n,t),this._executablesArray.push(n)}t.modules.forEach(t=>e.add(t))}await R.getInstance().initWithDlls(Array.from(e)),this.logger.log(`Raven updated, monitoring ${this._executableToGameMap.size} executables`),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=[]}}),B=E(class extends N{_processMonitor;_processes=new Map;boundOnRavenManagerExecutablesUpdated=this.onRavenManagerExecutablesUpdated.bind(this);constructor(){super(`ProcessManager`),this._processMonitor=new Ot}get hasAnyActiveProcesses(){return this.activeProcesses.length>0}get activeProcesses(){return Array.from(this._processes.values()).flat().filter(e=>!e.destroyedAt)}init(){super.init(),z.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(){z.getInstance().off(`executablesUpdated`,this.boundOnRavenManagerExecutablesUpdated),this._processes.clear(),this._processMonitor.removeAllListeners(),super.destroy()}isProcessRunning(e){return this._processes.get(e)?.some(e=>!e.destroyedAt)??!1}onRavenManagerExecutablesUpdated(e){this.logger.log(`Monitoring ${e.executables.length} processes`),e.executables.forEach(e=>{this._processMonitor.isProcessRegistered(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)?.filter(t=>t.id!==e.id)??[];t.length===0?this._processes.delete(e.name):this._processes.set(e.name,t)}});var Rt=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}}};const V=E(class{interfaces={};constructor(){}createInterface(e){return this.interfaces[e]||(this.interfaces[e]=new Rt(new He(e,{access:1}))),this.interfaces[e]}getInterface(e){return this.interfaces[e]?this.interfaces[e]:this.createInterface(e)}}),H=E(class{options;eventQueue;meta=null;constructor(e){this.options=this.resolveOptions(e),this.eventQueue=new xe,this.setupFlushInterval()}track(e,t){this.eventQueue.add({type:e,properties:t,created_at:new Date})}flush(){let e=Array.from(this.eventQueue.flush()).concat({type:`ping`,properties:{},created_at:new Date});if(!this.meta)throw Error(`Tried to flush Cortex events before meta was set`);try{xt({...this.meta,messages:e})}catch{}return e}setupFlushInterval(){setInterval(()=>{this.flush()},this.options.batchIntervalSeconds*1e3)}resolveOptions(e){return{batchIntervalSeconds:e?.batchIntervalSeconds??15}}}),U=e(import.meta.url),zt=U.resolve(`@overlayed/app/dist/render-interface/build/overlayed_render_hook_x64.dll`),Bt=U.resolve(`@overlayed/app/dist/render-interface/build/overlayed_render_hook_x86.dll`),Vt=U.resolve(`@overlayed/app/dist/native-interface/build/overlayed_native_interface_x64.node`),W=E(class extends $e{boundOnProcessCreate=this.onProcessCreate.bind(this);boundOnProcessDestroy=this.onProcessDestroy.bind(this);subscribedGames=new Set;_activeReadyRavenGames={};get isInGame(){return Object.keys(this._activeReadyRavenGames).length>0}constructor(){super(`GameLaunchManager`)}setSubscribedGames(e){this.subscribedGames=new Set(e)}getActiveGames(){return Object.keys(this._activeReadyRavenGames)}init(){super.init(),V.getInstance().createInterface(`OGG_SIEGE`),B.getInstance().on(`create`,this.boundOnProcessCreate),B.getInstance().on(`destroy`,this.boundOnProcessDestroy)}destroy(){B.getInstance().off(`create`,this.boundOnProcessCreate),B.getInstance().off(`destroy`,this.boundOnProcessDestroy),super.destroy()}on(e,t){super.on(e,t);let n=C(e);if(!(n.includes(`gameReady`)||n.includes(`*`))||Object.keys(this._activeReadyRavenGames).length===0)return;let r=t;for(let e of Object.values(this._activeReadyRavenGames))this.logger.log(`Late calling gameReady callback for game`,e.game),r(e)}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(H.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;let r=kt.currentProcess;if(this.logger.log(`Game Launched`,t),this.logger.log(`Process is elevated: `,e.isElevated),this.logger.log(`Current process is elevated: `,r.isElevated),e.isElevated&&!r.isElevated){D.getInstance().fatal(`Game is elevated but the App is not`,`ELEVATION_MISMATCH`,{appElevated:!!r.isElevated,gameElevated:!!e.isElevated}),this.logger.log(`Game elevated but App is not`,{appElevated:r.isElevated,gameElevated:e.isElevated});return}let{ri_disabled:i,gm_disabled:a}=Mt(),o=!1;!i&&t.has_render_support&&t.allow_dll_injections?o=await this.injectRenderInterface(e):this.logger.log(`Skipping render interface injection`,{has_render_support:t.has_render_support,allow_dll_injections:t.allow_dll_injections,ri_disabled:i}),!a&&t.allow_dll_injections?await this.injectGameModules(t,e):this.logger.log(`Skipping game module(s) injection`,{allow_dll_injections:t.allow_dll_injections,gm_disabled:a});let s={game:t.identifier,inGameRenderingSupported:o};this._activeReadyRavenGames[t.identifier]=s,this.logger.debug(`Active ready raven games`,Object.keys(this._activeReadyRavenGames).join(`, `)),this.logger.log(`Game Ready`),this.emit(`gameReadyInternal`,{ravenGame:t,process:e}),this.emit(`gameReady`,s),H.getInstance().track(`game_ready`,{game:t.identifier})}copyDll(e){let t=m.basename(e),n=g(e),r=m.join(k(),`resources`),i=m.join(r,t);this.logger.info(`Copying`,n,`to`,i);try{v(r)||ne(r,{recursive:!0}),ae(i,re(n)),ee(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 injectRenderInterface(e){this.logger.log(`Injecting render interface`,{is32Bit:e.is32Bit,process:e});let t=e.is32Bit?Bt:zt;this.logger.log(`Render hook path`,t);let n=this.copyDll(t);if(!n)return this.logger.error(`Failed to copy render hook DLL`,{renderHookPath:t}),!1;let r=m.join(m.dirname(Vt));if(!v(r))return this.logger.error(`Failed to find injector path`,{injectorPath:r}),!1;this.logger.log(`Resolved injector path`,r);try{return this.logger.log(`Injecting render interface`,n),await e.injectDll(n,r),this.logger.log(`Render Interface Injection Successful`,n),!0}catch(e){return this.logger.error(`Render Interface Injection Failed`,e),this.logger.error(`Render Interface Injection Failed`,{renderHookPathCopied:n}),!1}}async injectGameModules(e,t){let n=m.join(m.dirname(Vt));if(!v(n)){this.logger.error(`Failed to find injector path`,{injectorPath:n});return}this.logger.log(`Resolved injector path`,n);for(let r of e.modules){let e=await R.getInstance().getDllFile(r);if(!e){this.logger.error(`No DLL file found for module`,{moduleId:r});continue}try{this.logger.log(`Injecting game module`,e),await t.injectDll(e,n),this.logger.log(`Injection Successful`,e)}catch(t){this.logger.error(`Injection Failed`,{dllFile:e},t)}}}onProcessDestroy({process:e}){let t=this.getRavenGame(e);t&&(delete this._activeReadyRavenGames[t.identifier],this.logger.debug(`Active ready raven games`,Object.keys(this._activeReadyRavenGames).join(`, `)),this.emit(`gameCloseInternal`,{ravenGame:t,process:e}),this.emit(`gameClose`,{game:t.identifier}),H.getInstance().track(`game_close`,{game:t.identifier}))}getRavenGame(e){if(!e.name)return;let t=z.getInstance().getExecutableData(e.name);if(!t){this.logger.error(`No raven game found for process`,{process:e});return}return t}}),Ht=E(class extends Qe{boundOnGameLaunch=this.onGameLaunch.bind(this);constructor(){super(`GameBuildManager`)}init(){super.init(),W.getInstance().on(`gameReadyInternal`,this.boundOnGameLaunch)}destroy(){W.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=re(n.path),i=se(`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{a=(await vt(t.identifier,i)).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 b;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 Ae(s,{chunkSizeMb:25,maxConcurrent:1}),n=await yt(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 bt(t.identifier,{chunk:e,build_hash:i,chunk_index:r,upload_token:n.data.upload_token})}),this.logger.log(`Build uploaded successfully`)}catch(e){Ct(e)?wt(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)}}});function G(e,t){return`${e}:${t}`}function Ut(e,t,n){return e.reduce((e,r)=>{let i=r.key;return e[i]={on(e,n){let r=G(i,e),a=t.get(r)??new Set;a.add(n),t.set(r,a)},onAny(e){let n=G(i,`*`),r=t.get(n)??new Set;r.add(e),t.set(n,r)},off(e,n){let r=G(i,e),a=t.get(r);a&&(a.delete(n),a.size===0&&t.delete(r))},offAny(e){let n=G(i,`*`),r=t.get(n);r&&(r.delete(e),r.size===0&&t.delete(n))},readyForGameEvents:()=>{n.emit(`flushEvents`,i)}},e},{})}function Wt(){let e=D.getInstance(),t=W.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 K=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}(K||{});const q=new Map([[K.LeftButton,`LeftButton`],[K.RightButton,`RightButton`],[K.Cancel,`Cancel`],[K.MiddleButton,`MiddleButton`],[K.ExtraButton1,`ExtraButton1`],[K.ExtraButton2,`ExtraButton2`],[K.Back,`Backspace`],[K.Tab,`Tab`],[K.Clear,`Clear`],[K.Return,`Enter`],[K.Shift,`ShiftLeft`],[K.Control,`ControlLeft`],[K.Menu,`AltLeft`],[K.Pause,`Pause`],[K.CapsLock,`CapsLock`],[K.Kana,`KanaMode`],[K.Junja,`JunjaMode`],[K.Final,`Finalize`],[K.Hanja,`HanjaMode`],[K.Escape,`Escape`],[K.Convert,`Convert`],[K.NonConvert,`NonConvert`],[K.Accept,`Accept`],[K.ModeChange,`ModeChange`],[K.Space,`Space`],[K.Prior,`PageUp`],[K.Next,`PageDown`],[K.End,`End`],[K.Home,`Home`],[K.Left,`ArrowLeft`],[K.Up,`ArrowUp`],[K.Right,`ArrowRight`],[K.Down,`ArrowDown`],[K.Select,`Select`],[K.Print,`PrintScreen`],[K.Execute,`Execute`],[K.Snapshot,`Snapshot`],[K.Insert,`Insert`],[K.Delete,`Delete`],[K.Help,`Help`],[K.N0,`Digit0`],[K.N1,`Digit1`],[K.N2,`Digit2`],[K.N3,`Digit3`],[K.N4,`Digit4`],[K.N5,`Digit5`],[K.N6,`Digit6`],[K.N7,`Digit7`],[K.N8,`Digit8`],[K.N9,`Digit9`],[K.A,`KeyA`],[K.B,`KeyB`],[K.C,`KeyC`],[K.D,`KeyD`],[K.E,`KeyE`],[K.F,`KeyF`],[K.G,`KeyG`],[K.H,`KeyH`],[K.I,`KeyI`],[K.J,`KeyJ`],[K.K,`KeyK`],[K.L,`KeyL`],[K.M,`KeyM`],[K.N,`KeyN`],[K.O,`KeyO`],[K.P,`KeyP`],[K.Q,`KeyQ`],[K.R,`KeyR`],[K.S,`KeyS`],[K.T,`KeyT`],[K.U,`KeyU`],[K.V,`KeyV`],[K.W,`KeyW`],[K.X,`KeyX`],[K.Y,`KeyY`],[K.Z,`KeyZ`],[K.LeftWindows,`MetaLeft`],[K.RightWindows,`MetaRight`],[K.Application,`ContextMenu`],[K.Sleep,`Sleep`],[K.Numpad0,`Numpad0`],[K.Numpad1,`Numpad1`],[K.Numpad2,`Numpad2`],[K.Numpad3,`Numpad3`],[K.Numpad4,`Numpad4`],[K.Numpad5,`Numpad5`],[K.Numpad6,`Numpad6`],[K.Numpad7,`Numpad7`],[K.Numpad8,`Numpad8`],[K.Numpad9,`Numpad9`],[K.Multiply,`NumpadMultiply`],[K.Add,`NumpadAdd`],[K.Separator,`NumpadSeparator`],[K.Subtract,`NumpadSubtract`],[K.Decimal,`NumpadDecimal`],[K.Divide,`NumpadDivide`],[K.F1,`F1`],[K.F2,`F2`],[K.F3,`F3`],[K.F4,`F4`],[K.F5,`F5`],[K.F6,`F6`],[K.F7,`F7`],[K.F8,`F8`],[K.F9,`F9`],[K.F10,`F10`],[K.F11,`F11`],[K.F12,`F12`],[K.F13,`F13`],[K.F14,`F14`],[K.F15,`F15`],[K.F16,`F16`],[K.F17,`F17`],[K.F18,`F18`],[K.F19,`F19`],[K.F20,`F20`],[K.F21,`F21`],[K.F22,`F22`],[K.F23,`F23`],[K.F24,`F24`],[K.NumLock,`NumLock`],[K.ScrollLock,`ScrollLock`],[K.NEC_Equal,`NEC_Equal`],[K.Fujitsu_Masshou,`Fujitsu_Masshou`],[K.Fujitsu_Touroku,`Fujitsu_Touroku`],[K.Fujitsu_Loya,`Fujitsu_Loya`],[K.Fujitsu_Roya,`Fujitsu_Roya`],[K.LeftShift,`ShiftLeft`],[K.RightShift,`ShiftRight`],[K.LeftControl,`ControlLeft`],[K.RightControl,`ControlRight`],[K.LeftMenu,`AltLeft`],[K.RightMenu,`AltRight`],[K.BrowserBack,`BrowserBack`],[K.BrowserForward,`BrowserForward`],[K.BrowserRefresh,`BrowserRefresh`],[K.BrowserStop,`BrowserStop`],[K.BrowserSearch,`BrowserSearch`],[K.BrowserFavorites,`BrowserFavorites`],[K.BrowserHome,`BrowserHome`],[K.VolumeMute,`VolumeMute`],[K.VolumeDown,`VolumeDown`],[K.VolumeUp,`VolumeUp`],[K.MediaNextTrack,`MediaTrackNext`],[K.MediaPrevTrack,`MediaTrackPrevious`],[K.MediaStop,`MediaStop`],[K.MediaPlayPause,`MediaPlayPause`],[K.LaunchMail,`LaunchMail`],[K.LaunchMediaSelect,`LaunchMediaSelect`],[K.LaunchApplication1,`LaunchApplication1`],[K.LaunchApplication2,`LaunchApplication2`],[K.OEM1,`OEM_1`],[K.OEMPlus,`Equal`],[K.OEMComma,`Comma`],[K.OEMMinus,`Minus`],[K.OEMPeriod,`Period`],[K.OEM2,`Slash`],[K.OEM3,`Backquote`],[K.OEM4,`BracketLeft`],[K.OEM5,`Backslash`],[K.OEM6,`BracketRight`],[K.OEM7,`Quote`],[K.OEM8,`IntlRo`],[K.OEMAX,`OEM_AX`],[K.OEM102,`IntlBackslash`],[K.ICOHelp,`ICO_HELP`],[K.ICO00,`ICO_00`],[K.ProcessKey,`Process`],[K.ICOClear,`ICO_CLEAR`],[K.Packet,`Packet`],[K.OEMReset,`OEM_Reset`],[K.OEMJump,`OEM_Jump`],[K.OEMPA1,`OEM_PA1`],[K.OEMPA2,`OEM_PA2`],[K.OEMPA3,`OEM_PA3`],[K.OEMWSCtrl,`OEM_WS_Ctrl`],[K.OEMCUSel,`OEM_CU_Sel`],[K.OEMATTN,`OEM_ATTN`],[K.OEMFinish,`OEM_Finish`],[K.OEMCopy,`OEM_Copy`],[K.OEMAuto,`OEM_Auto`],[K.OEMENLW,`OEM_ENLW`],[K.OEMBackTab,`BackTab`],[K.ATTN,`ATTN`],[K.CRSel,`CRSel`],[K.EXSel,`EXSel`],[K.EREOF,`EREOF`],[K.Play,`MediaPlay`],[K.Zoom,`Zoom`],[K.Noname,`Noname`],[K.PA1,`PA1`],[K.OEMClear,`OEM_Clear`]]),Gt=new Map(q.entries().map(([e,t])=>[t,e])),Kt=r({"[string]":{keys:`string[]`,mode:r(`'toggle' | 'hold'`).pipe(e=>e??`toggle`)}});var qt=class extends N{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 O({path:F([`keybinds.json`]),schema:Kt,default:e})}init(){super.init();let e=V.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)??{toggle:[],down:[],up:[]};n.toggle.push(t),this.preferencesKeybindToCallbacks.set(e,n)}async onKeybindDown(e,t){let n=this.preferencesKeybindToCallbacks.get(e)??{toggle:[],down:[],up:[]};n.down.push(t),this.preferencesKeybindToCallbacks.set(e,n)}async onKeybindUp(e,t){let n=this.preferencesKeybindToCallbacks.get(e)??{toggle:[],down:[],up:[]};n.up.push(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=V.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=q.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=q.get(e.key);if(!t)return;this.pressedKeys.delete(t);let n=this.keybindsFile.get();for(let[e]of this.preferencesKeybindToCallbacks.entries())n[e].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||n.up.length===0)continue;let r=e[t];if(this.activeKeybinds.has(t)&&r.keys.some(e=>!this.pressedKeys.has(e))){this.activeKeybinds.delete(t);for(let e of n.up)e();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];if(r.keys.length===this.pressedKeys.size&&r.keys.every(e=>Gt.has(e)?this.pressedKeys.has(e):!1)){this.triggerKeybind(r,n,t);return}}for(let[t,n]of this.preferencesKeybindToCallbacks.entries()){let r=e[t];r.keys.every(e=>Gt.has(e)?this.pressedKeys.has(e):(this.logger.error(`Unknown key`,e,r),!1))&&this.triggerKeybind(r,n,t)}}triggerKeybind(e,t,n){let r=e.mode;if(r===`toggle`&&t.toggle&&t.toggle.length>0&&!this.triggeredToggleKeybinds.has(n)){let r;for(let e of t.toggle){let t=e();typeof t==`string`&&r===void 0&&(r=t)}this.triggeredToggleKeybinds.add(n),this.logger.log(r?`Keybind pressed rejected: ${r}`:`Keybind pressed accepted`,this.getKeybindToString(e))}if(r===`hold`&&t.down&&t.down.length>0&&!this.activeKeybinds.has(n)){let r;for(let e of t.down){let t=e();if(typeof t==`string`){r=t;break}}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 Jt(e){let t=new qt(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(),x.on(`quit`,()=>{t.destroy()}),r}function J(){return V.getInstance().getInterface(`OGG_SIEGE`)}function Yt(){let e=W.getInstance(),t=D.getInstance(),n=H.getInstance();n.meta=Y(),e.on([`gameReady`,`gameClose`],()=>{n.meta||=Y(),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 Y(){return{app_id:global.OVERLAYED.APPLICATION_ID,user_id:L(),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 Xt(){function e(e,t){return e.once(`closed`,()=>{e.isDestroyed()||H.getInstance().track(`window_closed`,{url:e.webContents.getURL(),in_game:t})}),e.on(`unresponsive`,()=>{e.isDestroyed()||H.getInstance().track(`window_unresponsive`,{url:e.webContents.getURL(),in_game:t})}),H.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(J().instance.newWindowInternal(global.OVERLAYED.electron.BrowserWindow,t),!0),on:(e,t)=>J().instance.on(e,t),off:(e,t)=>J().instance.off(e,t),once:(e,t)=>J().instance.once(e,t),addListener:(e,t)=>J().instance.addListener(e,t),removeListener:(e,t)=>J().instance.removeListener(e,t),removeAllListeners:()=>J().instance.removeAllListeners(),prependListener:(e,t)=>J().instance.prependListener(e,t),prependOnceListener:(e,t)=>J().instance.prependOnceListener(e,t),getActiveGameInfo:()=>{let e=J(),t=j.getInstance();return{resolution:e.resolution,isConnected:t.hasConnection}}}}const Zt=E(class extends Qe{renderInterface;globalCursorOverrideCount=new Set;globalMouseBlockCount=new Set;globalKeyboardBlockCount=new Set;keyInputBlocks={};constructor(e){super(`OverridesManager`),this.renderInterface=V.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)}},`OGG_SIEGE`);function Qt(){return{scope:e=>Zt.getInstance().scope(e),raw:{setGlobalMouseBlock:e=>J().instance.setGlobalMouseBlock(e),setGlobalKeyboardBlock:e=>J().instance.setGlobalKeyboardBlock(e),setGlobalCursorOverride:e=>J().instance.setGlobalCursorOverride(e),setKeyInputBlock:(e,t)=>J().instance.setKeyInputBlock(e,t),getGlobalMouseBlock:()=>J().instance.getGlobalMouseBlock(),getGlobalKeyboardBlock:()=>J().instance.getGlobalKeyboardBlock(),getGlobalCursorOverride:()=>J().instance.getGlobalCursorOverride(),getKeyInputBlock:e=>J().instance.getKeyInputBlock(e)}}}function $t(){return{track:(e,t)=>{H.getInstance().track(`custom__${String(e)}`,t)}}}var en=ge(((e,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`)for(let t of Object.values({KEYDOWN:256,LBUTTONUP:514,MBUTTONUP:520,RBUTTONUP:517,XBUTTONUP:524,TOUCH:576}))e.hookWindowMessage(t,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}}))();function tn(){return{registerWindow:e=>{(0,en.setupRevUtils)(e,global.OVERLAYED.electron)}}}function nn(e){let t=De(global.OVERLAYED.APPLICATION_ID),n=je(t,{recursive:!0}),r=Te(),i=je(r,{recursive:!0});A.getInstance().info(`Logs path: `,t),A.getInstance().info(`Overlayed logs path: `,r);let a=new b;return[...n,...i].forEach(([e,t])=>{A.getInstance().info(`Zipping: `,t);let n=te(t),r=h(t);a.file(r,n,{compression:`DEFLATE`})}),Object.entries(e?.additionalFiles??{}).forEach(([e,t])=>{A.getInstance().info(`Zipping extra file: `,e),a.file(e,t,{compression:`DEFLATE`})}),a}async function rn(e,t,n){let r={...t,category:e,version:`${global.OVERLAYED.APP_VERSION}@${global.OVERLAYED.APP_BUILD_CHANNEL}`,log_zip:`data:application/zip;base64,${n}`},{app_version:i,app_channel:a,user_id:o}=Y();try{let e=await fetch(`https://api.stats.cc/v1/overlay/contact`,{method:`POST`,body:JSON.stringify(r),redirect:`follow`,headers:{"Content-Type":`application/json`}});if(!e.ok){A.getInstance().error(`OLD - Failed to submit feedback`,await e.json());return}}catch(e){A.getInstance().error(`OLD - Failed to submit feedback`,e);return}return dt(global.OVERLAYED.APPLICATION_ID,{file:Buffer.from(n,`base64`),data:{app_version:i,app_channel:a,type:e,cortex_user_id:o,...t}}).then(e=>(A.getInstance().info(`Feedback submitted`,e),e.data.id)).catch(e=>{console.error(JSON.stringify(e,null,2)),A.getInstance().error(`Failed to submit feedback`,e)})}function an(e){let t=new ke(`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),submitFeedback:async(e,t,n)=>(H.getInstance().track(e===`bug_report`?`bug_report_submitted`:`suggestion_submitted`,{version:global.OVERLAYED.APP_VERSION,channel:global.OVERLAYED.APP_BUILD_CHANNEL}),await rn(e,t,await nn(n).generateAsync({type:`base64`})))}}const X=1e3;function on(e,t,n,i,a){let o=j.getInstance(),s=A.getInstance().scope(`SetupPipeServer`);s.log(`Initializing`);function c(e,t){let r=n.get(t);if(!r)n.set(t,[e]);else{if(r.length>=X){D.getInstance().warn(`Event buffer full, removing oldest event`,`EVENT_BUFFER_FULL`,{summary:`Event buffer overflow for module ${t}. Buffer size: ${r.length}, max: ${X}`});return}r.push(e)}}function l(n){s.info(n);let i=jt(n);if(i instanceof r.errors){H.getInstance().track(`invalid_game_event`,{}),D.getInstance().warn(`Invalid event`,`INVALID_EVENT`,{summary:i.summary});return}let o=Xe.includes(i.type),l=e.modules.find(e=>e.key===`universal`),u=o?l:e.modules.find(e=>e.key===i.game);if(!u){s.warn(`Invalid module`,{module:o?`universal`:i.game});return}let d=u.events.event,f=d(n);if(f instanceof r.errors){if(`type`in f.byPath)return;s.warn(`Invalid event`,{summary:f.summary}),H.getInstance().track(`invalid_game_event`,{game:i.game,type:i.type,summary:f.summary}),D.getInstance().warn(`Invalid event`,`INVALID_EVENT`,{summary:f.summary});return}if(!a[u.key]){c(f,u.key);return}if(f.type===`unsupported_game_version`){let{content:e}=f;H.getInstance().track(`unsupported_game_version`,{game:f.game,hash:e.process_hash,version:e.game_version})}let p=G(u.key,f.type),m=G(u.key,`*`),h=t.get(p),g=t.get(m),_=[...Array.from(h??[]),...Array.from(g??[])];if(_.length===0){s.info(`No handlers found for event`,{event:f});return}_.forEach(e=>{e(f)})}return i.on(`flushEvents`,e=>{if(a[e])return;a[e]=!0;let t=n.get(e);t&&(A.getInstance().info(`Flushing ${t.length} events for module ${e}`),t.forEach(e=>l(e)),n.delete(e))}),o.on(`data`,e=>e.forEach(l)),o.on(`error`,e=>{s.error(`Pipe server error`,e),D.getInstance().error(`Pipe server error`,`PIPE_SERVER_ERROR`,{error:e})}),o.on(`connected`,()=>{s.log(`Pipe server connected`)}),o.on(`disconnected`,()=>{s.log(`Pipe server disconnected`)}),o}const sn=r({dismissedNotices:ye(r.string).array()}),cn=E(class extends N{NOTICE_FETCH_INTERVAL=1e3*60*5;MAX_DISMISSED_NOTICES=100;_noticeFetchInterval=null;_notices=[];_noticesFile;_boundOnGameReady=this.onGameReady.bind(this);get notices(){let e=this._noticesFile.get().dismissedNotices;return this._notices.filter(t=>!e.includes(t.id))}constructor(){super(`NoticeManager`),this._noticesFile=this.getNoticesFile(),this._noticesFile.load(),this.fetchNotices(),this.setupNoticeInterval(),W.getInstance().on(`gameReady`,this._boundOnGameReady)}destroy(){this._noticeFetchInterval&&=(clearInterval(this._noticeFetchInterval),null),W.getInstance().off(`gameReady`,this._boundOnGameReady),super.destroy()}dismissNotice(e){let t=this._notices.find(t=>t.id===e);if(!t||!t.dismissible)return;let n=this._noticesFile.get().dismissedNotices;n.unshift(e),this._noticesFile.set({dismissedNotices:n.slice(0,this.MAX_DISMISSED_NOTICES)}),this.emitNoticesUpdated()}onGameReady(){this.fetchNotices()}setupNoticeInterval(){this._noticeFetchInterval=setInterval(()=>{this.fetchNotices()},this.NOTICE_FETCH_INTERVAL)}getNoticesFile(){return new O({path:F([`notices.json`]),schema:sn,default:{dismissedNotices:[]}})}async fetchNotices(){let e=W.getInstance().getActiveGames();try{let{data:t}=await ft(global.OVERLAYED.APPLICATION_ID,{channel:global.OVERLAYED.APP_BUILD_CHANNEL,version:global.OVERLAYED.APP_VERSION,games:e});this._notices=t,this.emitNoticesUpdated()}catch(e){this.logger.error(`Failed to fetch notices`,e)}}emitNoticesUpdated(){this.emit(`noticesUpdated`,{notices:this.notices})}});function ln(){let e=cn.getInstance();return{on:(t,n)=>{e.on(t,n)},off:(t,n)=>{e.off(t,n)},dismissNotice:t=>{e.dismissNotice(t)},getNotices:()=>e.notices}}let Z=!1,un={},Q,dn=new T,$;function fn(e){mn(e);let t=pn(e),{init:n=!0,debug:r=!1,silent:i=!0}=t;if(hn(e),A.getInstance().init(e.applicationId,r,i),Z)return Q;function a(){if(Z){A.getInstance().warn(`Overlayed already initialized`);return}Yt();let e=new Map,n=new Map,r=Ut(t.modules,e,dn),i=Wt(),o=Jt(t.keybinds),s=Xt(),c=Qt(),l=tn(),u=$t(),d=an(t),f=ln();A.getInstance().log(`Overlayed initialized`),gn(t),on(t,e,n,dn,un),Z=!0,Q={...r,...i,ads:l,keybinds:o,windows:s,input:c,cortex:u,hasAnyActiveProcesses:()=>B.getInstance().hasAnyActiveProcesses,hasAnyActiveGames:()=>W.getInstance().isInGame,init:a,log:d,initialized:Z,notices:f},Q.universal.on(`logged_in`,e=>{H.getInstance().track(`account_id`,{account_id:e.content.account_id,game:e.game})})}return n?(a(),Q):new Proxy({init:a},{get:(e,t)=>{if(t!==`init`&&!Z)throw Error(`overlayed was called before initialized: ${t}`);return t===`init`?e[t]:Q[t]}})}function pn(e){return{...e,modules:[...e.modules,Ze()]}}global.OVERLAYED=new Proxy({},{get:()=>{throw Error(`function overlayed was not called`)}});function mn(e){if(!be(e.applicationId))throw Error(`Invalid applicationId, must be a valid ULID.`)}function hn(e){global.OVERLAYED={APPLICATION_ID:lt(e.applicationId),APP_BUILD_CHANNEL:e.channel??`alpha`,APP_VERSION:e.version??`0.0.0`,PACKAGE_VERSION:`0.34.8`,FRONTEND_VERSION:`0.0.0`,sessionId:Nt(),electron:e.electron},it(()=>({package_version:global.OVERLAYED.PACKAGE_VERSION}))}function gn(e){let t=e.universal?[`*`]:e.modules.map(e=>e.key);W.getInstance().setSubscribedGames(t),Ht.getInstance().init(),W.getInstance().init(),B.getInstance().init(),z.getInstance().init();async function n(){let e=ut(global.OVERLAYED.APPLICATION_ID).then(e=>e.data),t=L();A.getInstance().log(`userId`,t);let n={...await e,userId:t};return A.getInstance().log(`appInfo`,n),n}let r;global.OVERLAYED.electron.ipcMain.handle(`getAppInfo`,async()=>(r??=n(),r)),H.getInstance().track(`start`,{});try{$&&clearInterval($),$=setInterval(()=>{try{Pt()}catch{}},3e4),$.unref()}catch(e){A.getInstance().log(`failed to start sessionLastUsed interval`,e)}async function i(){let e={};e.os=S.platform().trim(),e.os_version=process.getSystemVersion().trim(),e.architecture=S.arch().trim();let t=S.cpus();t.length>0?(e.cpu=t[0].model.trim(),e.cpu_cores=t.length,e.cpu_speed=t[0].speed):A.getInstance().warn(`Failed to collect CPU info`);let n=await le.graphics();A.getInstance().info(`GPU info`,n);let r=n.controllers.sort((e,t)=>(t.vram??0)-(e.vram??0))[0];r?(e.gpu=r.model.trim(),e.gpu_memory=r.vram??0):A.getInstance().warn(`Failed to find primary GPU`),e.display_count=n.displays.length;let i=n.displays.find(e=>e.main)??n.displays[0];i?(e.primary_display_resolution_x=i.resolutionX??void 0,e.primary_display_resolution_y=i.resolutionY??void 0,e.primary_display_refresh_rate=i.currentRefreshRate??void 0):A.getInstance().warn(`Failed to find main display`),e.ram=process.getSystemMemoryInfo().total;let a=S.homedir(),o=await ce.statfs(a);return o&&`blocks`in o&&`bsize`in o&&`bavail`in o?(e.disk=o.blocks*o.bsize,e.disk_free=o.bavail*o.bsize):A.getInstance().warn(`Failed to collect disk info`),A.getInstance().log(`Retrieved system information`,e),e}x.on(`ready`,()=>{i().then(e=>{H.getInstance().track(`system_info`,e)}).catch(e=>{A.getInstance().log(`Failed to retrieve system information`,e)})}),x.on(`quit`,()=>{H.getInstance().track(`electron_quit`,{}),_n()}),process.on(`exit`,()=>{H.getInstance().track(`exit`,{}),_n()})}async function _n(){try{Pt()}catch{}try{$&&clearInterval($),$=void 0}catch{}await H.getInstance().flush(),z.getInstance().destroy(),W.getInstance().destroy(),Ht.getInstance().destroy(),B.getInstance().destroy(),V.getInstance().getInterface(`OGG_SIEGE`).destroy(),j.getInstance().destroy(),D.getInstance().destroy()}export{He as RenderInterface,We as VirtualKey,Pe as defineConfig,fn as overlayed,Lt as setFetchLatestTokenCallback,nt as setUpdaterTokenResolver};
package/package.json CHANGED
@@ -2,7 +2,7 @@
2
2
  "name": "@overlayed/app",
3
3
  "author": "overlayed.gg",
4
4
  "homepage": "https://overlayed.gg",
5
- "version": "0.34.7",
5
+ "version": "0.34.8",
6
6
  "description": "Overlayed app",
7
7
  "license": "SEE LICENSE IN LICENSE.md",
8
8
  "repository": {