yolkbot 0.1.4-alpha.27 → 0.1.4-alpha.29

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/dist/bot.js CHANGED
@@ -1,3 +1,3 @@
1
1
  /* eslint-disable */
2
2
 
3
- import{createAccount as B,loginAnonymously as L,loginWithCredentials as $,loginWithRefreshToken as D,queryServices as I}from"./api.js";import a from"./comm/CommIn.js";import P from"./comm/CommOut.js";import{CommCode as r}from"./constants/codes.js";import x from"./bot/GamePlayer.js";import W from"./matchmaker.js";import H from"./socket.js";import{ChiknWinnerDailyLimit as j,CollectTypes as C,CoopStates as w,findItemById as g,GameActions as v,GameModes as k,GameOptionFlags as T,GunList as K,IsBrowser as q,ItemTypes as Y,Movements as _,PlayTypes as Z,ProxiesEnabled as J,ShellStreaks as p}from"./constants/index.js";import R from"./dispatches/LookAtPosDispatch.js";import M from"./dispatches/MovementDispatch.js";import{NodeList as V}from"./pathing/mapnode.js";import{Challenges as X}from"./constants/challenges.js";import{Maps as U}from"./constants/maps.js";const E=Object.fromEntries(Object.entries(w).map(([y,e])=>[e,y])),O=Object.fromEntries(Object.entries(k).map(([y,e])=>[e,y])),F={CHALLENGES:1,STATS:2,PATHFINDING:3,BUFFERS:4,PING:5,COSMETIC_DATA:6,PLAYER_HEALTH:7,PACKET_HOOK:8,MONITOR:9,LOG_PACKETS:10,NO_LOGIN:11};class Q{static Intents=F;Intents=F;#t=[];#s=[];#e={};#o=[];#a=[];constructor(e={}){if(e.proxy&&!J)throw new Error("proxies do not work and hence are not supported in the browser");this.intents=e.intents||[],this.instance=e.instance||"shellshock.io",this.protocol=e.protocol||"wss",this.proxy=e.proxy||"",this.autoUpdate=e.doUpdate||!0,this.updateInterval=e.updateInterval||16.5,this.state={name:"",weaponIdx:0,reloading:!1,swappingGun:!1,usingMelee:!1,shotsFired:0,quit:!1},this.players={},this.me=new x(this.id,0,{}),this.game={raw:{},code:"",socket:null,gameModeId:0,gameMode:O[0],mapIdx:0,map:{filename:"",hash:"",name:"",modes:{FFA:!1,Teams:!1,Spatula:!1,King:!1},availability:"both",numPlayers:"18",raw:{},nodes:{},zones:[]},playerLimit:0,isGameOwner:!1,isPrivate:!0,options:{gravity:1,damage:1,healthRegen:1,locked:!1,noTeamChange:!1,noTeamShuffle:!1,weaponsDisabled:Array(7).fill(!1),mustUseSecondary:!1},collectables:[[],[]],teamScore:[0,0,0],spatula:{coords:{x:0,y:0,z:0},controlledBy:0,controlledByTeam:0},stage:w.capturing,zoneNumber:0,activeZone:[],capturing:0,captureProgress:0,numCapturing:0,stageName:"",capturePercent:0},this.account={id:0,firebaseId:"",sessionId:"",session:"",email:"",password:"",cw:{atLimit:!1,limit:0,secondsUntilPlay:0,canPlayAgain:Date.now()},loadout:{hatId:null,meleeId:0,stampId:null,classIdx:0,colorIdx:0,grenadeId:0,primaryId:[3100,3600,3400,3800,4e3,4200,4500],secondaryId:new Array(7).fill(3e3),stampPositionX:0,stampPositionY:0},ownedItemIds:[],vip:!1,accountAge:0,emailVerified:!1,eggBalance:0,rawLoginData:{}},this.matchmaker=null,this.ping=0,this.lastPingTime=-1,this.lastDeathTime=-1,this.lastChatTime=-1,this.lastUpdateTime=-1,this.controlKeys=0,this.pathing={nodeList:null,followingPath:!1,activePath:null,activeNode:null,activeNodeIdx:0},this.intents.includes(this.Intents.PLAYER_HEALTH)&&(this.healthIntervalId=setInterval(()=>{if(this.players){for(const t of Object.values(this.players))if(t.playing&&t.hp>0){const s=.1*(this.game.isPrivate?this.game.options.healthRegen:1);t.streakRewards.includes(p.OverHeal)?t.hp=Math.max(100,t.hp-s):t.hp=Math.min(100,t.hp+s)}}},33))}dispatch(e){this.#t.push(e)}async createAccount(e,t){this.account.email=e,this.account.password=t;const s=await B(e,t,this.proxy,`${this.protocol}://${this.instance}`);return await this.#n(s)}async login(e,t){this.account.email=e,this.account.password=t;const s=await $(e,t,this.proxy,`${this.protocol}://${this.instance}`);return await this.#n(s)}async loginWithRefreshToken(e){const t=await D(e,this.proxy,`${this.protocol}://${this.instance}`);return await this.#n(t)}async loginAnonymously(){delete this.account.email,delete this.account.password;const e=await L(this.proxy,`${this.protocol}://${this.instance}`);return await this.#n(e)}async#n(e){return typeof e!="object"?(this.emit("authFail",e),!1):e.banRemaining?(this.emit("banned",e.banRemaining),!1):e.playerOutput?(e=e.playerOutput,this.account.rawLoginData=e,this.account.accountAge=e.accountAge,this.account.eggBalance=e.currentBalance,this.account.emailVerified=e.emailVerified,this.account.firebaseId=e.firebaseId,this.account.id=e.id,this.account.loadout=e.loadout,this.account.ownedItemIds=e.ownedItemIds,this.account.session=e.session,this.account.sessionId=e.sessionId,this.account.vip=e.upgradeProductId&&!e.upgradeIsExpired,this.intents.includes(this.Intents.STATS)&&(this.account.stats={lifetime:e.statsLifetime,monthly:e.statsCurrent}),this.intents.includes(this.Intents.CHALLENGES)&&this.#i(e.challenges),this.emit("authSuccess",this.account),this.account):(this.emit("authFail",e),!1)}#i(e){this.account.challenges=[];for(const t of e){const s=X.find(n=>n.id==t.challengeId);s&&(delete t.playerId,this.account.challenges.push({raw:{challengeInfo:s,challengeData:t},id:t.challengeId,name:s.loc.title,desc:s.loc.desc,rewardEggs:s.reward,isRerolled:!!t.reset,isClaimed:!!t.claimed,isCompleted:!!t.completed,progressNum:t.progress,goalNum:s.goal}))}}async initMatchmaker(){return!this.account.sessionId&&!this.intents.includes(this.Intents.NO_LOGIN)&&!await this.loginAnonymously()?!1:(this.matchmaker||(this.matchmaker=new W({sessionId:this.account.sessionId,proxy:this.proxy,instance:this.instance,protocol:this.protocol,noLogin:this.intents.includes(this.Intents.NO_LOGIN)}),this.matchmaker.on("authFail",e=>this.emit("authFail",e)),await this.matchmaker.getRegions()),!0)}async#r(e){return await this.initMatchmaker()?await new Promise(t=>{const s=n=>{if(n.command=="gameFound"&&(this.matchmaker.off("msg",s),this.game.raw=n,this.game.code=n.id,t()),n.error&&n.error=="gameNotFound")throw new Error(`Game ${e} not found (likely expired).`)};this.matchmaker.on("msg",s),this.matchmaker.send({command:"joinGame",id:e,observe:!1,sessionId:this.account.sessionId})}):!1}async createPrivateGame(e={}){if(!await this.initMatchmaker())return!1;if(!e.region)throw new Error('pass a region: createPrivateGame({ region: "useast", ... })');if(!this.matchmaker.regionList.find(n=>n.id==e.region))throw new Error('invalid region, see <bot>.matchmaker.regionList for a region list (pass an "id")');if(!e.mode)throw new Error('pass a mode: createPrivateGame({ mode: "ffa", ... })');if(k[e.mode]==null)throw new Error("invalid mode, see GameModes for a list");if(!e.map)throw new Error('pass a map: createPrivateGame({ map: "downfall", ... })');const t=U.find(n=>n.name.toLowerCase()==e.map.toLowerCase()),s=U.indexOf(t);if(s==-1)throw new Error("invalid map, see the Maps constant for a list");return await new Promise(n=>{const i=o=>{o.command=="gameFound"&&(this.matchmaker.off("msg",i),this.game.raw=o,this.game.code=this.game.raw.id,n())};this.matchmaker.on("msg",i),this.matchmaker.send({command:"findGame",region:e.region,playType:Z.createPrivate,gameType:k[e.mode],sessionId:this.account.sessionId,noobLobby:!1,map:s})}),this.game.raw}async join(e,t){if(this.state.name=e||"yolkbot",typeof t=="string"?(t.includes("#")&&(t=t.split("#")[1]),await this.#r(t)):typeof t=="object"&&(this.account.id==0&&await this.loginAnonymously(),this.game.raw=t,this.game.code=this.game.raw.id),!this.game.raw.id)throw new Error("invalid game data passed to <bot>.join");const s=async()=>{try{const n=this.instance.startsWith("localhost:")?this.instance:`${this.game.raw.subdomain}.${this.instance}`;this.game.socket=new H(`${this.protocol}://${n}/game/${this.game.raw.id}`,this.proxy),this.game.socket.onerror=async i=>(console.error(i),await new Promise(o=>setTimeout(o,100)),await s())}catch{await new Promise(n=>setTimeout(n,100)),await s()}};await s(),this.game.socket.binaryType="arraybuffer",this.game.socket.onopen=()=>this.game.socket.onerror=null,this.game.socket.onmessage=n=>this.processPacket(n.data),this.game.socket.onclose=n=>{this.emit("close",n.code),this.quit(!0,!0)}}#h(){if(Object.entries(this.me.position).map(t=>Math.floor(t[1])).join(",")==this.pathing.activePath[this.pathing.activePath.length-1].positionStr)this.pathing.followingPath=!1,this.pathing.activePath=null,this.pathing.activeNode=null,this.pathing.activeNodeIdx=0,this.dispatch(new M(0));else{let t;this.pathing.activeNodeIdx<this.pathing.activePath.length-1?(t=this.pathing.activePath[this.pathing.activeNodeIdx+1].flatCenter(),this.dispatch(new R(t))):(t=this.pathing.activePath[this.pathing.activeNodeIdx].flatCenter(),this.dispatch(new R(t)));for(const s of this.pathing.activePath)if(s.flatRadialDistance(this.me.position)<.1&&s.position.y==Math.floor(this.me.position.y)&&this.pathing.activePath.indexOf(s)>=this.pathing.activeNodeIdx){this.pathing.activeNodeIdx=this.pathing.activePath.indexOf(s)+1,this.pathing.activeNode=this.pathing.activePath[this.pathing.activeNodeIdx];break}this.controlKeys&_.FORWARD||this.dispatch(new M(_.FORWARD))}}update(){if(!this.state.joinedGame)throw new Error("You cannot call update() if the bot is not in a game.");if(this.state.quit)return;for(this.pathing.followingPath&&this.intents.includes(this.Intents.PATHFINDING)&&this.#h();this.#s.length>0;)this.processPacket(this.#s.shift());if(this.#t.length>0)for(let t=0;t<this.#t.length;t++){const s=this.#t[t];if(s.check(this)){s.execute(this),this.#t.splice(t,1);break}}const e=Date.now();if(e-this.lastUpdateTime>=50){if(this.emit("tick"),!this.intents.includes(this.Intents.MONITOR)){const t=P.getBuffer();t.packInt8(r.syncMe),t.packInt8(Math.random()*128|0),t.packInt8(this.me.serverStateIdx);for(let s=0;s<3;s++)t.packInt8(this.controlKeys),t.packInt8(this.state.shotsFired),t.packRadU(this.me.view.yaw),t.packRad(this.me.view.pitch),t.packInt8(100);t.send(this.game.socket)}this.lastUpdateTime=e,this.state.shotsFired=0}for(;this.#a.length>0;)this.#a.shift()()}on(e,t){Object.keys(this.#e).includes(e)?this.#e[e].push(t):this.#e[e]=[t]}onAny(e){this.#o.push(e)}#c=["authSuccess","authFail","banned","gameReady","importMap","quit"];emit(e,...t){if(!this.state.quit){if(this.#e[e])for(const s of this.#e[e])this.#c.includes(e)?s(...t):this.#a.push(()=>s(...t));for(const s of this.#o)this.#c.includes(e)?s(e,...t):this.#a.push(()=>s(e,...t))}}async#l(e,t){if(q){const s=await(await fetch(`https://esm.sh/gh/yolkorg/maps/maps/${e}.json`)).json();return this.emit("importMap",e,s),s}else{const{existsSync:s,mkdirSync:n,readFileSync:i,writeFileSync:o}=await import("node:fs"),{join:c}=await import("node:path"),{homedir:l}=await import("node:os"),m=c(l(),".yolkbot"),u=c(m,"maps");s(m)||n(m),s(u)||n(u);const h=c(u,`${e}-${t}.json`);if(s(h))return JSON.parse(i(h,"utf-8"));const f=await(await fetch(`https://${this.instance}/maps/${e}.json?${t}`)).json();return this.emit("importMap",e,f),o(h,JSON.stringify(f,null,4),{flag:"w+"}),f}}#m(){const e=this.game.map.raw.data["DYNAMIC.capture-zone.none"];if(!e)return delete this.game.map.zones;let t=0;const s={},n=[];for(const c of e)s[c.x]||(s[c.x]={}),s[c.x][c.y]||(s[c.x][c.y]={}),s[c.x][c.y][c.z]={zone:null};const i=[{x:-1,z:0},{x:1,z:0},{x:0,z:-1},{x:0,z:1}];function o(c,l,m){return s[c]&&s[c][l]&&s[c][l][m]?s[c][l][m]:null}for(const c of e)if(!s[c.x][c.y][c.z].zone){c.zone=++t,s[c.x][c.y][c.z].zone=c.zone;const l=[c];let m;do{m=0;for(const u of e)if(!s[u.x][u.y][u.z].zone)for(const h of i){const f=o(u.x+h.x,u.y,u.z+h.z);if(f&&f.zone==c.zone){m++,u.zone=c.zone,s[u.x][u.y][u.z].zone=c.zone,l.push(u);break}}}while(m>0);n.push(l)}this.game.map.zones=n}#u(){const e=a.unPackInt8U(),t=a.unPackInt8U(),s=a.unPackString(),n=this.players[e];this.emit("chat",n,s,t)}#d(){const e=a.unPackInt8U(),t=this.intents.includes(this.Intents.COSMETIC_DATA),s={id_:e,uniqueId_:a.unPackString(),name_:a.unPackString(),safename_:a.unPackString(),charClass_:a.unPackInt8U(),team_:a.unPackInt8U(),primaryWeaponItem_:t?g(a.unPackInt16U()):a.unPackInt16U(),secondaryWeaponItem_:t?g(a.unPackInt16U()):a.unPackInt16U(),shellColor_:a.unPackInt8U(),hatItem_:t?g(a.unPackInt16U()):a.unPackInt16U(),stampItem_:t?g(a.unPackInt16U()):a.unPackInt16U(),_unused:a.unPackInt8(),_unused2:a.unPackInt8(),grenadeItem_:t?g(a.unPackInt16U()):a.unPackInt16U(),meleeItem_:t?g(a.unPackInt16U()):a.unPackInt16U(),x_:a.unPackFloat(),y_:a.unPackFloat(),z_:a.unPackFloat(),dx_:a.unPackFloat(),dy_:a.unPackFloat(),dz_:a.unPackFloat(),yaw_:a.unPackRadU(),pitch_:a.unPackRad(),score_:a.unPackInt32U(),kills_:a.unPackInt16U(),deaths_:a.unPackInt16U(),streak_:a.unPackInt16U(),totalKills_:a.unPackInt32U(),totalDeaths_:a.unPackInt32U(),bestGameStreak_:a.unPackInt16U(),bestOverallStreak_:a.unPackInt16U(),shield_:a.unPackInt8U(),hp_:a.unPackInt8U(),playing_:a.unPackInt8U(),weaponIdx_:a.unPackInt8U(),controlKeys_:a.unPackInt8U(),upgradeProductId_:a.unPackInt8U(),activeShellStreaks_:a.unPackInt8U(),social_:a.unPackLongString(),hideBadge_:a.unPackInt8U()};s.gameData_={},s.gameData_.mapIdx=a.unPackInt8U(),s.gameData_.private=a.unPackInt8U(),s.gameData_.gameType=a.unPackInt8U(),this.players[s.id_]||(this.players[s.id_]=new x(s.id_,s.team_,s)),this.me.id==s.id_&&(this.me=this.players[s.id_]),this.emit("playerJoin",this.players[s.id_])}#p(){const e=a.unPackInt8U(),t=a.unPackInt16U(),s=a.unPackFloat(),n=a.unPackFloat(),i=a.unPackFloat(),o=a.unPackInt8U(),c=a.unPackInt8U(),l=a.unPackInt8U(),m=a.unPackInt8U(),u=a.unPackInt8U(),h=this.players[e];h&&(h.playing=!0,h.randomSeed=t,h.weapons[0]&&h.weapons[0].ammo&&(h.weapons[0].ammo.rounds=o),h.weapons[0]&&h.weapons[0].ammo&&(h.weapons[0].ammo.store=c),h.weapons[1]&&h.weapons[1].ammo&&(h.weapons[1].ammo.rounds=l),h.weapons[1]&&h.weapons[1].ammo&&(h.weapons[1].ammo.store=m),h.grenades=u,h.position={x:s,y:n,z:i},this.emit("playerRespawn",h))}#g(){const e=a.unPackInt8U(),t=a.unPackFloat(),s=a.unPackFloat(),n=a.unPackFloat(),i=a.unPackInt8U(),o=this.players[e];if(!o||o.id==this.me.id){for(let c=0;c<3;c++)a.unPackInt8U(),a.unPackRadU(),a.unPackRad(),a.unPackInt8U();return}if(o.position.x!==t&&(o.position.x=t),o.position.z!==n&&(o.position.z=n),(!o.jumping||Math.abs(o.position.y-s)>.5&&o.position.y!==s)&&(o.position.y=s),o.climbing!==i&&(o.climbing=i),this.intents.includes(this.Intents.BUFFERS)){if(!o.buffer)return;for(let c=0;c<3;c++){o.buffer[c].controlKeys=a.unPackInt8U();const l=a.unPackRadU();isNaN(l)||(o.buffer[c].yaw_=l);const m=a.unPackRad();isNaN(m)||(o.buffer[c].pitch_=m),a.unPackInt8U()}o.buffer[0].x=t,o.buffer[0].y=s,o.buffer[0].z=n}else for(let c=0;c<3;c++)a.unPackInt8U(),a.unPackRadU(),a.unPackRad(),a.unPackInt8U()}#k(){const e=a.unPackInt8U(),t=this.players[e];t&&(t.playing=!1,this.emit("playerPause",t))}#I(){const e=a.unPackInt8U(),t=a.unPackInt8U(),s=this.players[e];s&&(s.activeGun=t,this.emit("playerSwapWeapon",s,t))}#f(){const e=a.unPackInt8U(),t=a.unPackInt8U();a.unPackInt8U(),a.unPackInt8U(),a.unPackInt8U();const s=this.players[e],n=this.players[t];s&&(s.playing=!1,s.streak=0,s.lastDeathTime=Date.now(),s.hp=100,s.hpShield=0),n&&n.streak++,this.emit("playerDeath",s,n)}#P(){const e=a.unPackInt8U();for(let n=0;n<6;n++)a.unPackFloat();const t=this.players[e],s=t.weapons[t.activeGun];s&&s.ammo&&(s.ammo.rounds--,this.emit("playerFire",t,s))}#y(){const e=a.unPackInt16U(),t=a.unPackInt8U(),s=a.unPackFloat(),n=a.unPackFloat(),i=a.unPackFloat();this.game.collectables[t].push({id:e,x:s,y:n,z:i}),this.emit("spawnItem",t,e,{x:s,y:n,z:i})}#w(){const e=a.unPackInt8U(),t=a.unPackInt8U(),s=a.unPackInt8U(),n=a.unPackInt16U(),i=this.players[e];if(this.game.collectables[t]=this.game.collectables[t].filter(o=>o.id!=n),t==C.AMMO){const o=i.weapons[s];o&&o.ammo&&(o.ammo.store=Math.min(o.ammo.storeMax,o.ammo.store+o.ammo.pickup),this.emit("collectAmmo",i,o))}t==C.GRENADE&&(i.grenades++,i.grenades>3&&(i.grenades=3),this.emit("collectGrenade",i))}#U(){const e=a.unPackInt8U(),t=a.unPackInt8U(),s=this.players[e];if(!s)return;const n=s.hp;s.hp=t,this.emit("playerDamaged",s,n,s.hp)}#b(){const e=a.unPackInt8U();a.unPackFloat(),a.unPackFloat();const t=this.me.hp;this.me.hp=e,this.emit("selfDamaged",t,this.me.hp)}#S(){const e=a.unPackInt8U(),t=this.players[e];a.unPackInt8U();const s=a.unPackInt8U(),n=a.unPackFloat(),i=a.unPackFloat(),o=a.unPackFloat();if(a.unPackInt8U(),a.unPackInt8U(),a.unPackInt8U(),!t)return;t.serverStateIdx=s;const c=t.position.x,l=t.position.y,m=t.position.z;t.position.x=n,t.position.y=i,t.position.z=o,(c!=n||l!=i||m!=o)&&this.emit("selfMoved",t,{x:c,y:l,z:m},{x:n,y:i,z:o})}#x(){if(!this.intents.includes(this.Intents.MONITOR)){const e=P.getBuffer();e.packInt8(r.eventModifier),e.send(this.game.socket)}}#C(){const e=a.unPackInt8U(),t={...this.players[e]};delete this.players[e.toString()],this.emit("playerLeave",t)}#v(){if(this.game.gameModeId==k.spatula){this.game.teamScore[1]=a.unPackInt16U(),this.game.teamScore[2]=a.unPackInt16U();const e={x:a.unPackFloat(),y:a.unPackFloat(),z:a.unPackFloat()},t=a.unPackInt8U(),s=a.unPackInt8U();this.game.spatula={coords:e,controlledBy:t,controlledByTeam:s},this.emit("gameStateChange",this.game)}else this.game.gameModeId==k.kotc?(this.game.stage=a.unPackInt8U(),this.game.zoneNumber=a.unPackInt8U(),this.game.capturing=a.unPackInt8U(),this.game.captureProgress=a.unPackInt16U(),this.game.numCapturing=a.unPackInt8U(),this.game.teamScore[1]=a.unPackInt8U(),this.game.teamScore[2]=a.unPackInt8U(),this.game.stageName=E[this.game.stage],this.game.capturePercent=this.game.captureProgress/1e3,this.game.activeZone=this.game.map.zones?this.game.map.zones[this.game.zoneNumber-1]:null,this.emit("gameStateChange",this.game)):this.game.gameModeId==k.team&&(this.game.teamScore[1]=a.unPackInt16U(),this.game.teamScore[2]=a.unPackInt16U());this.game.gameModeId!==k.spatula&&delete this.game.spatula,this.game.gameModeId!==k.kotc&&(delete this.game.stage,delete this.game.zoneNumber,delete this.game.capturing,delete this.game.captureProgress,delete this.game.numCapturing,delete this.game.stageName,delete this.game.numCapturing,delete this.game.activeZone),this.game.gameModeId==k.ffa&&delete this.game.teamScore}#T(){const e=a.unPackInt8U(),t=a.unPackInt8U(),s=this.players[e];switch(t){case p.HardBoiled:s.hpShield=100,s.streakRewards.push(p.HardBoiled);break;case p.EggBreaker:s.streakRewards.push(p.EggBreaker);break;case p.Restock:{s.grenades=3,s.weapons[0]&&s.weapons[0].ammo&&(s.weapons[0].ammo.rounds=s.weapons[0].ammo.capacity,s.weapons[0].ammo.store=s.weapons[0].ammo.storeMax),s.weapons[1]&&s.weapons[1].ammo&&(s.weapons[1].ammo.rounds=s.weapons[1].ammo.capacity,s.weapons[1].ammo.store=s.weapons[1].ammo.storeMax);break}case p.OverHeal:s.hp=Math.min(200,s.hp+100),s.streakRewards.push(p.OverHeal);break;case p.DoubleEggs:s.streakRewards.push(p.DoubleEggs);break;case p.MiniEgg:s.streakRewards.push(p.MiniEgg);break}this.emit("playerBeginStreak",s,t)}#_(){const e=a.unPackInt8U(),t=a.unPackInt8U(),s=this.players[e];[p.EggBreaker,p.OverHeal,p.DoubleEggs,p.MiniEgg].includes(t)&&s.streakRewards.includes(t)&&(s.streakRewards=s.streakRewards.filter(i=>i!=t)),this.emit("playerEndStreak",t,s)}#R(){const e=a.unPackInt8U(),t=a.unPackInt8U();a.unPackFloat(),a.unPackFloat(),this.me.hpShield=e,this.me.hp=t,this.me.hpShield<=0?(this.me.streakRewards=this.me.streakRewards.filter(s=>s!=p.HardBoiled),this.emit("selfShieldLost")):this.emit("selfShieldHit",this.me.hpShield)}#M(){const e={...this.game.options};let t=a.unPackInt8U(),s=a.unPackInt8U(),n=a.unPackInt8U();(t<1||t>4)&&(t=4),(s<0||s>8)&&(s=4),n>16&&(n=4),this.game.options.gravity=t/4,this.game.options.damage=s/4,this.game.options.healthRegen=n/4;const i=a.unPackInt8U();return Object.keys(T).forEach(o=>{const c=i&T[o]?1:0;this.game.options[o]=c}),this.game.options.weaponsDisabled=Array.from({length:7},()=>a.unPackInt8U()===1),this.game.options.mustUseSecondary=this.game.options.weaponsDisabled.every(o=>o),this.emit("gameOptionsChange",e,this.game.options),!1}#E(){const e=a.unPackInt8U();e==v.pause&&(this.emit("gameForcePause"),setTimeout(()=>this.me.playing=!1,3e3)),e==v.reset&&(Object.values(this.players).forEach(t=>t.streak=0),this.game.gameModeId!==k.ffa&&(this.game.teamScore=[0,0,0]),this.game.gameModeId===k.spatula&&(this.game.spatula.controlledBy=0,this.game.spatula.controlledByTeam=0,this.game.spatula.coords={x:0,y:0,z:0}),this.game.gameModeId===k.kotc&&(this.game.stage=w.capturing,this.game.zoneNumber=0,this.game.activeZone=null,this.game.capturing=0,this.game.captureProgress=0,this.game.numCapturing=0,this.game.stageName=E[w.capturing],this.game.capturePercent=0),this.emit("gameReset"))}#O(){if(!this.intents.includes(this.Intents.PING))return;const e=this.ping;this.ping=Date.now()-this.lastPingTime,this.emit("pingUpdate",e,this.ping),this.intents.includes(this.Intents.MONITOR)||setTimeout(()=>{const t=P.getBuffer();t.packInt8(r.ping),t.send(this.game.socket),this.lastPingTime=Date.now()},this.pingInterval)}#F(){const e=a.unPackInt8U(),t=a.unPackInt8U(),s=this.players[e];if(!s)return;const n=s.team;s.team=t,s.streak=0,this.emit("playerSwitchTeam",s,n,t)}#G(){const e=a.unPackInt8U(),t=a.unPackInt8U(),s=a.unPackInt16U(),n=a.unPackInt16U(),i=a.unPackInt8U(),o=a.unPackInt16U(),c=a.unPackInt16U(),l=a.unPackInt16U(),m=a.unPackInt16U();a.unPackInt8(),a.unPackInt8();const u=this.intents.includes(this.Intents.COSMETIC_DATA),h=u?g(s):s,f=u?g(n):n,G=u?g(o):o,A=u?g(c):c,N=u?g(l):l,z=u?g(m):m,d=this.players[e];if(d){const b={...d.character},S=d.selectedGun;d.character.eggColor=i,d.character.primaryGun=h,d.character.secondaryGun=f,d.character.stamp=A,d.character.hat=G,d.character.grenade=N,d.character.melee=z,d.selectedGun=t,d.weapons[0]=new K[t],S!==d.selectedGun&&this.emit("playerChangeGun",d,S,d.selectedGun),b!==d.character&&this.emit("playerChangeCharacter",d,b,d.character)}}#A(){const e=a.unPackInt32U(),t=this.account.eggBalance;this.account.eggBalance=e,this.emit("balanceUpdate",e-t,e)}#N(){this.me.playing=!1,this.emit("selfRespawnFail")}#z(){const e=a.unPackInt8U(),t=this.players[e];t&&this.emit("playerMelee",t)}#B(){const e=a.unPackInt8U(),t=this.players[e];if(!t)return;const s=t.weapons[t.activeGun];if(s.ammo){const n=Math.min(Math.min(s.ammo.capacity,s.ammo.reload)-s.ammo.rounds,s.ammo.store);s.ammo.rounds+=n,s.ammo.store-=n}this.emit("playerReload",t,s)}#L(){if(!this.intents.includes(this.Intents.MONITOR)){const e=P.getBuffer();e.packInt8(r.gameOptions),e.packInt8(this.game.options.gravity*4),e.packInt8(this.game.options.damage*4),e.packInt8(this.game.options.healthRegen*4);const t=(this.game.options.locked?1:0)|(this.game.options.noTeamChange?2:0)|(this.game.options.noTeamShuffle?4:0);e.packInt8(t),this.game.options.weaponsDisabled.forEach(s=>{e.packInt8(s?1:0)}),e.send(this.game.socket)}}#$(){const e=a.unPackInt8U();let t=a.unPackInt16U();const s=a.unPackFloat(),n=a.unPackFloat(),i=a.unPackFloat(),o=a.unPackInt8U(),c=a.unPackFloat();this.intents.includes(this.Intents.COSMETIC_DATA)&&(t=g(t)),e==Y.Grenade?this.emit("grenadeExploded",t,{x:s,y:n,z:i},o,c):this.emit("rocketHit",{x:s,y:n,z:i},o,c)}#D(){const e=a.unPackInt8U(),t=a.unPackFloat(),s=a.unPackFloat(),n=a.unPackFloat(),i=a.unPackFloat(),o=a.unPackFloat(),c=a.unPackFloat(),l=this.players[e];l&&(l.grenades--,this.emit("playerThrowGrenade",l,{x:t,y:s,z:n},{x:i,y:o,z:c}))}#W(){const e=a.unPackInt8U(),t=a.unPackInt8U(),s=this.players[e];if(!s)return;if(!this.intents.includes(this.Intents.CHALLENGES))return this.emit("challengeComplete",s,t);const n=this.account.challenges.find(i=>i.id==t);this.emit("challengeComplete",s,n),s.id==this.me.id&&this.refreshChallenges()}#H(){if(!this.intents.includes(this.Intents.MONITOR)){const e=P.getBuffer();e.packInt8(r.joinGame),e.packString(this.state.name),e.packString(this.game.raw.uuid),e.packInt8(0),e.packInt8(this.state.weaponIdx||0),e.packInt32(this.account.session),e.packString(this.account.firebaseId),e.packString(this.account.sessionId),e.send(this.game.socket)}}async#j(){if(this.me.id=a.unPackInt8U(),this.me.team=a.unPackInt8U(),this.game.gameModeId=a.unPackInt8U(),this.game.gameMode=O[this.game.gameModeId],this.game.mapIdx=a.unPackInt8U(),this.game.map=U[this.game.mapIdx],this.intents.includes(this.Intents.PATHFINDING)&&(this.game.map.raw=await this.#l(this.game.map.filename,this.game.map.hash),this.pathing.nodeList=new V(this.game.map.raw),this.game.gameModeId===k.kotc&&this.#m()),this.game.playerLimit=a.unPackInt8U(),this.game.isGameOwner=a.unPackInt8U()==1,this.game.isPrivate=a.unPackInt8U()==1,a.unPackInt8U(),this.state.joinedGame=!0,this.lastDeathTime=Date.now(),!this.intents.includes(this.Intents.MONITOR)){const e=P.getBuffer();e.packInt8(r.clientReady),e.send(this.game.socket),this.game.socket.onmessage=t=>this.#s.push(t.data)}if(this.autoUpdate&&(this.updateIntervalId=setInterval(()=>this.update(),this.updateInterval)),this.intents.includes(this.Intents.PING)&&(this.lastPingTime=Date.now(),!this.intents.includes(this.Intents.MONITOR))){const e=P.getBuffer();e.packInt8(r.ping),e.send(this.game.socket)}this.emit("gameReady")}processPacket(e){a.init(e),this.intents.includes(this.Intents.PACKET_HOOK)&&this.emit("packet",e);let t=0,s=0,n=!1;for(;a.isMoreDataAvailable()&&!n;){const i=a.unPackInt8U();switch(i){case r.syncThem:this.#g();break;case r.fire:this.#P();break;case r.hitThem:this.#U();break;case r.syncMe:this.#S();break;case r.hitMe:this.#b();break;case r.swapWeapon:this.#I();break;case r.collectItem:this.#w();break;case r.respawn:this.#p();break;case r.die:this.#f();break;case r.pause:this.#k();break;case r.chat:this.#u();break;case r.addPlayer:this.#d();break;case r.removePlayer:this.#C();break;case r.eventModifier:this.#x();break;case r.metaGameState:this.#v();break;case r.beginShellStreak:this.#T();break;case r.endShellStreak:this.#_();break;case r.hitMeHardBoiled:this.#R();break;case r.gameOptions:this.#M();break;case r.ping:this.#O();break;case r.switchTeam:this.#F();break;case r.changeCharacter:this.#G();break;case r.reload:this.#B();break;case r.explode:this.#$();break;case r.throwGrenade:this.#D();break;case r.spawnItem:this.#y();break;case r.melee:this.#z();break;case r.updateBalance:this.#A();break;case r.challengeCompleted:this.#W();break;case r.socketReady:this.#H();break;case r.gameJoined:this.#j();break;case r.gameAction:this.#E();break;case r.requestGameOptions:this.#L();break;case r.respawnDenied:this.#N();break;case r.expireUpgrade:case r.clientReady:break;case r.musicInfo:a.unPackLongString();break;default:console.error(`handlePacket: I got but did not handle a: ${Object.keys(r).find(o=>r[o]===i)} ${i}`),t&&console.error(`handlePacket: It may be a result of the ${t} command (${s}).`),n=!0;break}t=Object.keys(r).find(o=>r[o]===i),s=i,this.intents.includes(this.Intents.LOG_PACKETS)&&console.log(`[LOG_PACKETS] Packet ${t}: ${s}`)}}async checkChiknWinner(){const e=await I({cmd:"chicknWinnerReady",id:this.account.id,sessionId:this.account.sessionId});return typeof e=="string"?e:(this.account.cw.limit=e.limit,this.account.cw.atLimit=e.limit>=4,this.account.cw.secondsUntilPlay=(this.account.cw.atLimit?e.period:e.span)||0,this.account.cw.canPlayAgain=Date.now()+this.account.cw.secondsUntilPlay*1e3,this.account.cw)}async playChiknWinner(e=!0){if(this.account.cw.atLimit||this.account.cw.limit>j)return"hit_daily_limit";if(this.account.cw.canPlayAgain>Date.now()&&e)return"on_cooldown";const t=await I({cmd:"incentivizedVideoReward",firebaseId:this.account.firebaseId,id:this.account.id,sessionId:this.account.sessionId,token:null},this.proxy,`${this.protocol}://${this.instance}`);return typeof t=="string"?t:t.error?t.error=="RATELIMITED"||t.error=="RATELMITED"?(await this.checkChiknWinner(),"on_cooldown"):t.error=="SESSION_EXPIRED"?"session_expired":(console.error("Unknown Chikn Winner response",t),"unknown_error"):t.reward?(this.account.eggBalance+=t.reward.eggsGiven,t.reward.itemIds.forEach(s=>this.account.ownedItemIds.push(s)),await this.checkChiknWinner(),t.reward):(console.error("Unknown Chikn Winner response",t),"unknown_error")}async resetChiknWinner(){if(this.account.eggBalance<200)return"not_enough_eggs";if(!this.account.cw.atLimit)return"not_at_limit";const e=await I({cmd:"chwReset",sessionId:this.account.sessionId});return typeof e=="string"?e:e.result!=="SUCCESS"?(console.error("Unknown Chikn Winner reset response",e),"unknown_error"):(this.account.eggBalance-=200,await this.checkChiknWinner(),this.account.cw)}canSee(e){if(!this.intents.includes(this.Intents.PATHFINDING))throw new Error("You must have the PATHFINDING intent to use this method.");return this.pathing.nodeList.hasLineOfSight(this.me.position,e.position)}getBestTarget(e=()=>!0){const t=Object.values(this.players).filter(i=>i).filter(i=>i!==this.me).filter(i=>i.playing).filter(i=>i.hp>0).filter(i=>i.name!==this.me.name).filter(i=>this.me.team===0||i.team!==this.me.team).filter(i=>this.canSee(i)).filter(i=>!!e(i));let s=200,n=null;for(const i of t){const o=i.position.x-this.me.position.x,c=i.position.y-this.me.position.y,l=i.position.z-this.me.position.z,m=Math.sqrt(o*o+c*c+l*l);m<s&&(s=m,n=i)}return n}async refreshChallenges(){const e=await I({cmd:"challengeGetDaily",sessionId:this.account.sessionId,playerId:this.account.id},this.proxy,`${this.protocol}://${this.instance}`);return this.#i(e),this.account.challenges}async rerollChallenge(e){const t=await I({cmd:"challengeRerollSlot",sessionId:this.account.sessionId,slotId:e},this.proxy,`${this.protocol}://${this.instance}`);return this.#i(t),this.account.challenges}async claimChallenge(e){const t=await I({cmd:"challengeClaimReward",sessionId:this.account.sessionId,slotId:e},this.proxy,`${this.protocol}://${this.instance}`);return this.#i(t.challenges),{eggReward:t.reward,updatedChallenges:this.account.challenges}}async refreshBalance(){const e=await I({cmd:"checkBalance",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId},this.proxy,`${this.protocol}://${this.instance}`);return this.account.eggBalance=e.currentBalance,e.currentBalance}async redeemCode(e){const t=await I({cmd:"redeem",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,id:this.account.id,code:e},this.proxy,`${this.protocol}://${this.instance}`);return t.result==="SUCCESS"?(this.account.eggBalance=t.eggs_given,t.item_ids.forEach(s=>this.account.ownedItemIds.push(s)),{result:t,eggsGiven:t.eggs_given,itemIds:t.item_ids}):t}async claimURLReward(e){const t=await I({cmd:"urlRewardParams",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,reward:e},this.proxy,`${this.protocol}://${this.instance}`);return t.result==="SUCCESS"&&(this.account.eggBalance+=t.eggsGiven,t.itemIds.forEach(s=>this.account.ownedItemIds.push(s))),t}async claimSocialReward(e){const t=await I({cmd:"reward",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,rewardTag:e},this.proxy,`${this.protocol}://${this.instance}`);return t.result==="SUCCESS"&&(this.account.eggBalance+=t.eggsGiven,t.itemIds.forEach(s=>this.account.ownedItemIds.push(s))),t}async buyItem(e){const t=await I({cmd:"buy",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,itemId:e,save:!0},this.proxy,`${this.protocol}://${this.instance}`);return t.result==="SUCCESS"&&(this.account.eggBalance=t.currentBalance,this.account.ownedItemIds.push(t.itemId)),t}quit(e=!1,t=!1){this.state.quit||(this.intents.includes(this.Intents.PLAYER_HEALTH)&&clearInterval(this.healthIntervalId),clearInterval(this.updateIntervalId),this.game?.socket&&this.game.socket.close(),this.matchmaker&&this.matchmaker.close(),t||(this.#t=[]),this.#s=[],e||(delete this.account,delete this.game,delete this.me,delete this.players),this.state.quit=!0,this.emit("quit"))}}var dt=Q;export{Q as Bot,dt as default};
3
+ import{createAccount as L,loginAnonymously as D,loginWithCredentials as $,loginWithRefreshToken as z,queryServices as k}from"./api.js";import s from"./comm/CommIn.js";import f from"./comm/CommOut.js";import{CommCode as c}from"./constants/codes.js";import S from"./bot/GamePlayer.js";import W from"./matchmaker.js";import H from"./socket.js";import{ChiknWinnerDailyLimit as j,CollectTypes as C,CoopStates as y,findItemById as p,GameActions as v,GameModes as g,GameOptionFlags as x,GunList as K,ItemTypes as q,Movements as T,PlayTypes as Y,ProxiesEnabled as Z,ShellStreaks as u}from"./constants/index.js";import _ from"./dispatches/LookAtPosDispatch.js";import R from"./dispatches/MovementDispatch.js";import{NodeList as V}from"./pathing/mapnode.js";import{fetchMap as X,initKotcZones as J}from"./util.js";import{Challenges as Q}from"./constants/challenges.js";import{Maps as w}from"./constants/maps.js";const M=Object.fromEntries(Object.entries(y).map(([P,e])=>[e,P])),E=Object.fromEntries(Object.entries(g).map(([P,e])=>[e,P])),O={CHALLENGES:1,STATS:2,PATHFINDING:3,BUFFERS:4,PING:5,COSMETIC_DATA:6,PLAYER_HEALTH:7,PACKET_HOOK:8,MONITOR:9,LOG_PACKETS:10,NO_LOGIN:11};class tt{static Intents=O;Intents=O;#t=[];#s=[];#e={};#o=[];#a=[];constructor(e={}){if(e.proxy&&!Z)throw new Error("proxies do not work and hence are not supported in the browser");this.intents=e.intents||[],this.instance=e.instance||"shellshock.io",this.protocol=e.protocol||"wss",this.proxy=e.proxy||"",this.autoUpdate=e.doUpdate||!0,this.updateInterval=e.updateInterval||16.5,this.state={name:"",weaponIdx:0,reloading:!1,swappingGun:!1,usingMelee:!1,shotsFired:0,quit:!1},this.players={},this.me=new S(this.id,0,{}),this.game={raw:{},code:"",socket:null,gameModeId:0,gameMode:E[0],mapIdx:0,map:{filename:"",hash:"",name:"",modes:{FFA:!1,Teams:!1,Spatula:!1,King:!1},availability:"both",numPlayers:"18",raw:{},nodes:{},zones:[]},playerLimit:0,isGameOwner:!1,isPrivate:!0,options:{gravity:1,damage:1,healthRegen:1,locked:!1,noTeamChange:!1,noTeamShuffle:!1,weaponsDisabled:Array(7).fill(!1),mustUseSecondary:!1},collectables:[[],[]],teamScore:[0,0,0],spatula:{coords:{x:0,y:0,z:0},controlledBy:0,controlledByTeam:0},stage:y.capturing,zoneNumber:0,activeZone:[],capturing:0,captureProgress:0,numCapturing:0,stageName:"",capturePercent:0},this.account={id:0,firebaseId:"",sessionId:"",session:"",email:"",password:"",cw:{atLimit:!1,limit:0,secondsUntilPlay:0,canPlayAgain:Date.now()},loadout:{hatId:null,meleeId:0,stampId:null,classIdx:0,colorIdx:0,grenadeId:0,primaryId:[3100,3600,3400,3800,4e3,4200,4500],secondaryId:new Array(7).fill(3e3),stampPositionX:0,stampPositionY:0},ownedItemIds:[],vip:!1,accountAge:0,emailVerified:!1,eggBalance:0,rawLoginData:{}},this.matchmaker=null,this.ping=0,this.lastPingTime=-1,this.lastDeathTime=-1,this.lastChatTime=-1,this.lastUpdateTime=-1,this.controlKeys=0,this.pathing={nodeList:null,followingPath:!1,activePath:null,activeNode:null,activeNodeIdx:0},this.intents.includes(this.Intents.PLAYER_HEALTH)&&(this.healthIntervalId=setInterval(()=>{if(this.players){for(const t of Object.values(this.players))if(t.playing&&t.hp>0){const a=.1*(this.game.isPrivate?this.game.options.healthRegen:1);t.streakRewards.includes(u.OverHeal)?t.hp=Math.max(100,t.hp-a):t.hp=Math.min(100,t.hp+a)}}},33))}dispatch(e){this.#t.push(e)}async createAccount(e,t){this.account.email=e,this.account.password=t;const a=await L(e,t,this.proxy,`${this.protocol}://${this.instance}`);return await this.#n(a)}async login(e,t){this.account.email=e,this.account.password=t;const a=await $(e,t,this.proxy,`${this.protocol}://${this.instance}`);return await this.#n(a)}async loginWithRefreshToken(e){const t=await z(e,this.proxy,`${this.protocol}://${this.instance}`);return await this.#n(t)}async loginAnonymously(){delete this.account.email,delete this.account.password;const e=await D(this.proxy,`${this.protocol}://${this.instance}`);return await this.#n(e)}async#n(e){return typeof e!="object"?(this.emit("authFail",e),!1):e.banRemaining?(this.emit("banned",e.banRemaining),!1):e.playerOutput?(e=e.playerOutput,this.account.rawLoginData=e,this.account.accountAge=e.accountAge,this.account.eggBalance=e.currentBalance,this.account.emailVerified=e.emailVerified,this.account.firebaseId=e.firebaseId,this.account.id=e.id,this.account.loadout=e.loadout,this.account.ownedItemIds=e.ownedItemIds,this.account.session=e.session,this.account.sessionId=e.sessionId,this.account.vip=e.upgradeProductId&&!e.upgradeIsExpired,this.intents.includes(this.Intents.STATS)&&(this.account.stats={lifetime:e.statsLifetime,monthly:e.statsCurrent}),this.intents.includes(this.Intents.CHALLENGES)&&this.#i(e.challenges),this.emit("authSuccess",this.account),this.account):(this.emit("authFail",e),!1)}#i(e){this.account.challenges=[];for(const t of e){const a=Q.find(n=>n.id==t.challengeId);a&&(delete t.playerId,this.account.challenges.push({raw:{challengeInfo:a,challengeData:t},id:t.challengeId,name:a.loc.title,desc:a.loc.desc,rewardEggs:a.reward,isRerolled:!!t.reset,isClaimed:!!t.claimed,isCompleted:!!t.completed,progressNum:t.progress,goalNum:a.goal}))}}async initMatchmaker(){return!this.account.sessionId&&!this.intents.includes(this.Intents.NO_LOGIN)&&!await this.loginAnonymously()?!1:(this.matchmaker||(this.matchmaker=new W({sessionId:this.account.sessionId,proxy:this.proxy,instance:this.instance,protocol:this.protocol,noLogin:this.intents.includes(this.Intents.NO_LOGIN)}),this.matchmaker.on("authFail",e=>this.emit("authFail",e)),await this.matchmaker.getRegions()),!0)}async#r(e){return await this.initMatchmaker()?await new Promise(t=>{const a=n=>{if(n.command=="gameFound"&&(this.matchmaker.off("msg",a),this.game.raw=n,this.game.code=n.id,t()),n.error&&n.error=="gameNotFound")throw new Error(`Game ${e} not found (likely expired).`)};this.matchmaker.on("msg",a),this.matchmaker.send({command:"joinGame",id:e,observe:!1,sessionId:this.account.sessionId})}):!1}async createPrivateGame(e={}){if(!await this.initMatchmaker())return!1;if(!e.region)throw new Error('pass a region: createPrivateGame({ region: "useast", ... })');if(!this.matchmaker.regionList.find(n=>n.id==e.region))throw new Error('invalid region, see <bot>.matchmaker.regionList for a region list (pass an "id")');if(!e.mode)throw new Error('pass a mode: createPrivateGame({ mode: "ffa", ... })');if(g[e.mode]==null)throw new Error("invalid mode, see GameModes for a list");if(!e.map)throw new Error('pass a map: createPrivateGame({ map: "downfall", ... })');const t=w.find(n=>n.name.toLowerCase()==e.map.toLowerCase()),a=w.indexOf(t);if(a==-1)throw new Error("invalid map, see the Maps constant for a list");return await new Promise(n=>{const i=o=>{o.command=="gameFound"&&(this.matchmaker.off("msg",i),this.game.raw=o,this.game.code=this.game.raw.id,n())};this.matchmaker.on("msg",i),this.matchmaker.send({command:"findGame",region:e.region,playType:Y.createPrivate,gameType:g[e.mode],sessionId:this.account.sessionId,noobLobby:!1,map:a})}),this.game.raw}async join(e,t){if(this.state.name=e||"yolkbot",typeof t=="string"?(t.includes("#")&&(t=t.split("#")[1]),await this.#r(t)):typeof t=="object"&&(this.account.id==0&&await this.loginAnonymously(),this.game.raw=t,this.game.code=this.game.raw.id),!this.game.raw.id)throw new Error("invalid game data passed to <bot>.join");const a=async()=>{try{const n=this.instance.startsWith("localhost:")?this.instance:`${this.game.raw.subdomain}.${this.instance}`;this.game.socket=new H(`${this.protocol}://${n}/game/${this.game.raw.id}`,this.proxy),this.game.socket.onerror=async i=>(console.error(i),await new Promise(o=>setTimeout(o,100)),await a())}catch{await new Promise(n=>setTimeout(n,100)),await a()}};await a(),this.game.socket.binaryType="arraybuffer",this.game.socket.onopen=()=>this.game.socket.onerror=null,this.game.socket.onmessage=n=>this.processPacket(n.data),this.game.socket.onclose=n=>{this.emit("close",n.code),this.quit(!0,!0)}}#h(){if(Object.entries(this.me.position).map(t=>Math.floor(t[1])).join(",")==this.pathing.activePath[this.pathing.activePath.length-1].positionStr)this.pathing.followingPath=!1,this.pathing.activePath=null,this.pathing.activeNode=null,this.pathing.activeNodeIdx=0,this.dispatch(new R(0));else{let t;this.pathing.activeNodeIdx<this.pathing.activePath.length-1?(t=this.pathing.activePath[this.pathing.activeNodeIdx+1].flatCenter(),this.dispatch(new _(t))):(t=this.pathing.activePath[this.pathing.activeNodeIdx].flatCenter(),this.dispatch(new _(t)));for(const a of this.pathing.activePath)if(a.flatRadialDistance(this.me.position)<.1&&a.position.y==Math.floor(this.me.position.y)&&this.pathing.activePath.indexOf(a)>=this.pathing.activeNodeIdx){this.pathing.activeNodeIdx=this.pathing.activePath.indexOf(a)+1,this.pathing.activeNode=this.pathing.activePath[this.pathing.activeNodeIdx];break}this.controlKeys&T.FORWARD||this.dispatch(new R(T.FORWARD))}}update(){if(!this.state.joinedGame)throw new Error("You cannot call update() if the bot is not in a game.");if(this.state.quit)return;for(this.pathing.followingPath&&this.intents.includes(this.Intents.PATHFINDING)&&this.#h();this.#s.length>0;)this.processPacket(this.#s.shift());if(this.#t.length>0)for(let t=0;t<this.#t.length;t++){const a=this.#t[t];if(a.check(this)){a.execute(this),this.#t.splice(t,1);break}}const e=Date.now();if(e-this.lastUpdateTime>=50){if(this.emit("tick"),!this.intents.includes(this.Intents.MONITOR)){const t=f.getBuffer();t.packInt8(c.syncMe),t.packInt8(Math.random()*128|0),t.packInt8(this.me.serverStateIdx);for(let a=0;a<3;a++)t.packInt8(this.controlKeys),t.packInt8(this.state.shotsFired),t.packRadU(this.me.view.yaw),t.packRad(this.me.view.pitch),t.packInt8(100);t.send(this.game.socket)}this.lastUpdateTime=e,this.state.shotsFired=0}for(;this.#a.length>0;)this.#a.shift()()}on(e,t){Object.keys(this.#e).includes(e)?this.#e[e].push(t):this.#e[e]=[t]}onAny(e){this.#o.push(e)}#c=["authSuccess","authFail","banned","gameReady","quit"];emit(e,...t){if(!this.state.quit){if(this.#e[e])for(const a of this.#e[e])this.#c.includes(e)?a(...t):this.#a.push(()=>a(...t));for(const a of this.#o)this.#c.includes(e)?a(e,...t):this.#a.push(()=>a(e,...t))}}#l(){const e=s.unPackInt8U(),t=s.unPackInt8U(),a=s.unPackString().valueOf(),n=this.players[e];this.emit("chat",n,a,t)}#m(){const e=s.unPackInt8U(),t=this.intents.includes(this.Intents.COSMETIC_DATA),a={id_:e,uniqueId_:s.unPackString(),name_:s.unPackString(),safename_:s.unPackString(),charClass_:s.unPackInt8U(),team_:s.unPackInt8U(),primaryWeaponItem_:t?p(s.unPackInt16U()):s.unPackInt16U(),secondaryWeaponItem_:t?p(s.unPackInt16U()):s.unPackInt16U(),shellColor_:s.unPackInt8U(),hatItem_:t?p(s.unPackInt16U()):s.unPackInt16U(),stampItem_:t?p(s.unPackInt16U()):s.unPackInt16U(),_unused:s.unPackInt8(),_unused2:s.unPackInt8(),grenadeItem_:t?p(s.unPackInt16U()):s.unPackInt16U(),meleeItem_:t?p(s.unPackInt16U()):s.unPackInt16U(),x_:s.unPackFloat(),y_:s.unPackFloat(),z_:s.unPackFloat(),dx_:s.unPackFloat(),dy_:s.unPackFloat(),dz_:s.unPackFloat(),yaw_:s.unPackRadU(),pitch_:s.unPackRad(),score_:s.unPackInt32U(),kills_:s.unPackInt16U(),deaths_:s.unPackInt16U(),streak_:s.unPackInt16U(),totalKills_:s.unPackInt32U(),totalDeaths_:s.unPackInt32U(),bestGameStreak_:s.unPackInt16U(),bestOverallStreak_:s.unPackInt16U(),shield_:s.unPackInt8U(),hp_:s.unPackInt8U(),playing_:s.unPackInt8U(),weaponIdx_:s.unPackInt8U(),controlKeys_:s.unPackInt8U(),upgradeProductId_:s.unPackInt8U(),activeShellStreaks_:s.unPackInt8U(),social_:s.unPackLongString(),hideBadge_:s.unPackInt8U()};a.gameData_={},a.gameData_.mapIdx=s.unPackInt8U(),a.gameData_.private=s.unPackInt8U(),a.gameData_.gameType=s.unPackInt8U(),this.players[a.id_]||(this.players[a.id_]=new S(a.id_,a.team_,a)),this.me.id==a.id_&&(this.me=this.players[a.id_]),this.emit("playerJoin",this.players[a.id_])}#u(){const e=s.unPackInt8U(),t=s.unPackInt16U(),a=s.unPackFloat(),n=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackInt8U(),r=s.unPackInt8U(),m=s.unPackInt8U(),d=s.unPackInt8U(),I=s.unPackInt8U(),h=this.players[e];h&&(h.playing=!0,h.randomSeed=t,h.weapons[0]&&h.weapons[0].ammo&&(h.weapons[0].ammo.rounds=o),h.weapons[0]&&h.weapons[0].ammo&&(h.weapons[0].ammo.store=r),h.weapons[1]&&h.weapons[1].ammo&&(h.weapons[1].ammo.rounds=m),h.weapons[1]&&h.weapons[1].ammo&&(h.weapons[1].ammo.store=d),h.grenades=I,h.position={x:a,y:n,z:i},this.emit("playerRespawn",h))}#d(){const e=s.unPackInt8U(),t=s.unPackFloat(),a=s.unPackFloat(),n=s.unPackFloat(),i=s.unPackInt8U(),o=this.players[e];if(!o||o.id==this.me.id){for(let r=0;r<3;r++)s.unPackInt8U(),s.unPackRadU(),s.unPackRad(),s.unPackInt8U();return}if(o.position.x!==t&&(o.position.x=t),o.position.z!==n&&(o.position.z=n),(!o.jumping||Math.abs(o.position.y-a)>.5&&o.position.y!==a)&&(o.position.y=a),o.climbing!==i&&(o.climbing=i),this.intents.includes(this.Intents.BUFFERS)){if(!o.buffer)return;for(let r=0;r<3;r++){o.buffer[r].controlKeys=s.unPackInt8U();const m=s.unPackRadU();isNaN(m)||(o.buffer[r].yaw_=m);const d=s.unPackRad();isNaN(d)||(o.buffer[r].pitch_=d),s.unPackInt8U()}o.buffer[0].x=t,o.buffer[0].y=a,o.buffer[0].z=n}else for(let r=0;r<3;r++)s.unPackInt8U(),s.unPackRadU(),s.unPackRad(),s.unPackInt8U()}#p(){const e=s.unPackInt8U(),t=this.players[e];t&&(t.playing=!1,this.emit("playerPause",t))}#g(){const e=s.unPackInt8U(),t=s.unPackInt8U(),a=this.players[e];a&&(a.activeGun=t,this.emit("playerSwapWeapon",a,t))}#k(){const e=s.unPackInt8U(),t=s.unPackInt8U();s.unPackInt8U(),s.unPackInt8U(),s.unPackInt8U();const a=this.players[e],n=this.players[t];a&&(a.playing=!1,a.streak=0,a.lastDeathTime=Date.now(),a.hp=100,a.hpShield=0),n&&n.streak++,this.emit("playerDeath",a,n)}#I(){const e=s.unPackInt8U();for(let n=0;n<6;n++)s.unPackFloat();const t=this.players[e],a=t.weapons[t.activeGun];a&&a.ammo&&(a.ammo.rounds--,this.emit("playerFire",t,a))}#f(){const e=s.unPackInt16U(),t=s.unPackInt8U(),a=s.unPackFloat(),n=s.unPackFloat(),i=s.unPackFloat();this.game.collectables[t].push({id:e,x:a,y:n,z:i}),this.emit("spawnItem",t,e,{x:a,y:n,z:i})}#P(){const e=s.unPackInt8U(),t=s.unPackInt8U(),a=s.unPackInt8U(),n=s.unPackInt16U(),i=this.players[e];if(this.game.collectables[t]=this.game.collectables[t].filter(o=>o.id!=n),t==C.AMMO){const o=i.weapons[a];o&&o.ammo&&(o.ammo.store=Math.min(o.ammo.storeMax,o.ammo.store+o.ammo.pickup),this.emit("collectAmmo",i,o))}t==C.GRENADE&&(i.grenades++,i.grenades>3&&(i.grenades=3),this.emit("collectGrenade",i))}#y(){const e=s.unPackInt8U(),t=s.unPackInt8U(),a=this.players[e];if(!a)return;const n=a.hp;a.hp=t,this.emit("playerDamaged",a,n,a.hp)}#w(){const e=s.unPackInt8U();s.unPackFloat(),s.unPackFloat();const t=this.me.hp;this.me.hp=e,this.emit("selfDamaged",t,this.me.hp)}#U(){const e=s.unPackInt8U(),t=this.players[e];s.unPackInt8U();const a=s.unPackInt8U(),n=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackFloat();if(s.unPackInt8U(),s.unPackInt8U(),s.unPackInt8U(),!t)return;t.serverStateIdx=a;const r=t.position.x,m=t.position.y,d=t.position.z;t.position.x=n,t.position.y=i,t.position.z=o,(r!=n||m!=i||d!=o)&&this.emit("selfMoved",t,{x:r,y:m,z:d},{x:n,y:i,z:o})}#b(){if(!this.intents.includes(this.Intents.MONITOR)){const e=f.getBuffer();e.packInt8(c.eventModifier),e.send(this.game.socket)}}#S(){const e=s.unPackInt8U(),t={...this.players[e]};delete this.players[e.toString()],this.emit("playerLeave",t)}#C(){if(this.game.gameModeId==g.spatula){this.game.teamScore[1]=s.unPackInt16U(),this.game.teamScore[2]=s.unPackInt16U();const e={x:s.unPackFloat(),y:s.unPackFloat(),z:s.unPackFloat()},t=s.unPackInt8U(),a=s.unPackInt8U();this.game.spatula={coords:e,controlledBy:t,controlledByTeam:a},this.emit("gameStateChange",this.game)}else this.game.gameModeId==g.kotc?(this.game.stage=s.unPackInt8U(),this.game.zoneNumber=s.unPackInt8U(),this.game.capturing=s.unPackInt8U(),this.game.captureProgress=s.unPackInt16U(),this.game.numCapturing=s.unPackInt8U(),this.game.teamScore[1]=s.unPackInt8U(),this.game.teamScore[2]=s.unPackInt8U(),this.game.stageName=M[this.game.stage],this.game.capturePercent=this.game.captureProgress/1e3,this.game.activeZone=this.game.map.zones?this.game.map.zones[this.game.zoneNumber-1]:null,this.emit("gameStateChange",this.game)):this.game.gameModeId==g.team&&(this.game.teamScore[1]=s.unPackInt16U(),this.game.teamScore[2]=s.unPackInt16U());this.game.gameModeId!==g.spatula&&delete this.game.spatula,this.game.gameModeId!==g.kotc&&(delete this.game.stage,delete this.game.zoneNumber,delete this.game.capturing,delete this.game.captureProgress,delete this.game.numCapturing,delete this.game.stageName,delete this.game.numCapturing,delete this.game.activeZone),this.game.gameModeId==g.ffa&&delete this.game.teamScore}#v(){const e=s.unPackInt8U(),t=s.unPackInt8U(),a=this.players[e];switch(t){case u.HardBoiled:a.hpShield=100,a.streakRewards.push(u.HardBoiled);break;case u.EggBreaker:a.streakRewards.push(u.EggBreaker);break;case u.Restock:{a.grenades=3,a.weapons[0]&&a.weapons[0].ammo&&(a.weapons[0].ammo.rounds=a.weapons[0].ammo.capacity,a.weapons[0].ammo.store=a.weapons[0].ammo.storeMax),a.weapons[1]&&a.weapons[1].ammo&&(a.weapons[1].ammo.rounds=a.weapons[1].ammo.capacity,a.weapons[1].ammo.store=a.weapons[1].ammo.storeMax);break}case u.OverHeal:a.hp=Math.min(200,a.hp+100),a.streakRewards.push(u.OverHeal);break;case u.DoubleEggs:a.streakRewards.push(u.DoubleEggs);break;case u.MiniEgg:a.streakRewards.push(u.MiniEgg);break}this.emit("playerBeginStreak",a,t)}#x(){const e=s.unPackInt8U(),t=s.unPackInt8U(),a=this.players[e];[u.EggBreaker,u.OverHeal,u.DoubleEggs,u.MiniEgg].includes(t)&&a.streakRewards.includes(t)&&(a.streakRewards=a.streakRewards.filter(i=>i!=t)),this.emit("playerEndStreak",t,a)}#T(){const e=s.unPackInt8U(),t=s.unPackInt8U();s.unPackFloat(),s.unPackFloat(),this.me.hpShield=e,this.me.hp=t,this.me.hpShield<=0?(this.me.streakRewards=this.me.streakRewards.filter(a=>a!=u.HardBoiled),this.emit("selfShieldLost")):this.emit("selfShieldHit",this.me.hpShield)}#_(){const e={...this.game.options};let t=s.unPackInt8U(),a=s.unPackInt8U(),n=s.unPackInt8U();(t<1||t>4)&&(t=4),(a<0||a>8)&&(a=4),n>16&&(n=4),this.game.options.gravity=t/4,this.game.options.damage=a/4,this.game.options.healthRegen=n/4;const i=s.unPackInt8U();return Object.keys(x).forEach(o=>{const r=i&x[o]?1:0;this.game.options[o]=r}),this.game.options.weaponsDisabled=Array.from({length:7},()=>s.unPackInt8U()===1),this.game.options.mustUseSecondary=this.game.options.weaponsDisabled.every(o=>o),this.emit("gameOptionsChange",e,this.game.options),!1}#R(){const e=s.unPackInt8U();e==v.pause&&(this.emit("gameForcePause"),setTimeout(()=>this.me.playing=!1,3e3)),e==v.reset&&(Object.values(this.players).forEach(t=>t.streak=0),this.game.gameModeId!==g.ffa&&(this.game.teamScore=[0,0,0]),this.game.gameModeId===g.spatula&&(this.game.spatula.controlledBy=0,this.game.spatula.controlledByTeam=0,this.game.spatula.coords={x:0,y:0,z:0}),this.game.gameModeId===g.kotc&&(this.game.stage=y.capturing,this.game.zoneNumber=0,this.game.activeZone=null,this.game.capturing=0,this.game.captureProgress=0,this.game.numCapturing=0,this.game.stageName=M[y.capturing],this.game.capturePercent=0),this.emit("gameReset"))}#M(){if(!this.intents.includes(this.Intents.PING))return;const e=this.ping;this.ping=Date.now()-this.lastPingTime,this.emit("pingUpdate",e,this.ping),this.intents.includes(this.Intents.MONITOR)||setTimeout(()=>{const t=f.getBuffer();t.packInt8(c.ping),t.send(this.game.socket),this.lastPingTime=Date.now()},this.pingInterval)}#E(){const e=s.unPackInt8U(),t=s.unPackInt8U(),a=this.players[e];if(!a)return;const n=a.team;a.team=t,a.streak=0,this.emit("playerSwitchTeam",a,n,t)}#O(){const e=s.unPackInt8U(),t=s.unPackInt8U(),a=s.unPackInt16U(),n=s.unPackInt16U(),i=s.unPackInt8U(),o=s.unPackInt16U(),r=s.unPackInt16U(),m=s.unPackInt16U(),d=s.unPackInt16U();s.unPackInt8(),s.unPackInt8();const I=this.intents.includes(this.Intents.COSMETIC_DATA),h=I?p(a):a,G=I?p(n):n,F=I?p(o):o,A=I?p(r):r,N=I?p(m):m,B=I?p(d):d,l=this.players[e];if(l){const U={...l.character},b=l.selectedGun;l.character.eggColor=i,l.character.primaryGun=h,l.character.secondaryGun=G,l.character.stamp=A,l.character.hat=F,l.character.grenade=N,l.character.melee=B,l.selectedGun=t,l.weapons[0]=new K[t],b!==l.selectedGun&&this.emit("playerChangeGun",l,b,l.selectedGun),U!==l.character&&this.emit("playerChangeCharacter",l,U,l.character)}}#G(){const e=s.unPackInt32U(),t=this.account.eggBalance;this.account.eggBalance=e,this.emit("balanceUpdate",e-t,e)}#F(){this.me.playing=!1,this.emit("selfRespawnFail")}#A(){const e=s.unPackInt8U(),t=this.players[e];t&&this.emit("playerMelee",t)}#N(){const e=s.unPackInt8U(),t=this.players[e];if(!t)return;const a=t.weapons[t.activeGun];if(a.ammo){const n=Math.min(Math.min(a.ammo.capacity,a.ammo.reload)-a.ammo.rounds,a.ammo.store);a.ammo.rounds+=n,a.ammo.store-=n}this.emit("playerReload",t,a)}#B(){if(!this.intents.includes(this.Intents.MONITOR)){const e=f.getBuffer();e.packInt8(c.gameOptions),e.packInt8(this.game.options.gravity*4),e.packInt8(this.game.options.damage*4),e.packInt8(this.game.options.healthRegen*4);const t=(this.game.options.locked?1:0)|(this.game.options.noTeamChange?2:0)|(this.game.options.noTeamShuffle?4:0);e.packInt8(t),this.game.options.weaponsDisabled.forEach(a=>{e.packInt8(a?1:0)}),e.send(this.game.socket)}}#L(){const e=s.unPackInt8U();let t=s.unPackInt16U();const a=s.unPackFloat(),n=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackInt8U(),r=s.unPackFloat();this.intents.includes(this.Intents.COSMETIC_DATA)&&(t=p(t)),e==q.Grenade?this.emit("grenadeExploded",t,{x:a,y:n,z:i},o,r):this.emit("rocketHit",{x:a,y:n,z:i},o,r)}#D(){const e=s.unPackInt8U(),t=s.unPackFloat(),a=s.unPackFloat(),n=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackFloat(),r=s.unPackFloat(),m=this.players[e];m&&(m.grenades--,this.emit("playerThrowGrenade",m,{x:t,y:a,z:n},{x:i,y:o,z:r}))}#$(){const e=s.unPackInt8U(),t=s.unPackInt8U(),a=this.players[e];if(!a)return;if(!this.intents.includes(this.Intents.CHALLENGES))return this.emit("challengeComplete",a,t);const n=this.account.challenges.find(i=>i.id==t);this.emit("challengeComplete",a,n),a.id==this.me.id&&this.refreshChallenges()}#z(){if(!this.intents.includes(this.Intents.MONITOR)){const e=f.getBuffer();e.packInt8(c.joinGame),e.packString(this.state.name),e.packString(this.game.raw.uuid),e.packInt8(0),e.packInt8(this.state.weaponIdx||0),e.packInt32(this.account.session),e.packString(this.account.firebaseId),e.packString(this.account.sessionId),e.send(this.game.socket)}}async#W(){if(this.me.id=s.unPackInt8U(),this.me.team=s.unPackInt8U(),this.game.gameModeId=s.unPackInt8U(),this.game.gameMode=E[this.game.gameModeId],this.game.mapIdx=s.unPackInt8U(),this.game.map=w[this.game.mapIdx],this.intents.includes(this.Intents.PATHFINDING)&&(this.game.map.raw=await X(this.game.map.filename,this.game.map.hash),this.pathing.nodeList=new V(this.game.map.raw),this.game.gameModeId===g.kotc)){const e=this.game.map.raw.data["DYNAMIC.capture-zone.none"];e?this.game.map.zones=J(e):delete this.game.map.zones}if(this.game.playerLimit=s.unPackInt8U(),this.game.isGameOwner=s.unPackInt8U()==1,this.game.isPrivate=s.unPackInt8U()==1,s.unPackInt8U(),this.state.joinedGame=!0,this.lastDeathTime=Date.now(),!this.intents.includes(this.Intents.MONITOR)){const e=f.getBuffer();e.packInt8(c.clientReady),e.send(this.game.socket),this.game.socket.onmessage=t=>this.#s.push(t.data)}if(this.autoUpdate&&(this.updateIntervalId=setInterval(()=>this.update(),this.updateInterval)),this.intents.includes(this.Intents.PING)&&(this.lastPingTime=Date.now(),!this.intents.includes(this.Intents.MONITOR))){const e=f.getBuffer();e.packInt8(c.ping),e.send(this.game.socket)}this.emit("gameReady")}processPacket(e){s.init(e),this.intents.includes(this.Intents.PACKET_HOOK)&&this.emit("packet",e);let t=0,a=0,n=!1;for(;s.isMoreDataAvailable()&&!n;){const i=s.unPackInt8U();switch(i){case c.syncThem:this.#d();break;case c.fire:this.#I();break;case c.hitThem:this.#y();break;case c.syncMe:this.#U();break;case c.hitMe:this.#w();break;case c.swapWeapon:this.#g();break;case c.collectItem:this.#P();break;case c.respawn:this.#u();break;case c.die:this.#k();break;case c.pause:this.#p();break;case c.chat:this.#l();break;case c.addPlayer:this.#m();break;case c.removePlayer:this.#S();break;case c.eventModifier:this.#b();break;case c.metaGameState:this.#C();break;case c.beginShellStreak:this.#v();break;case c.endShellStreak:this.#x();break;case c.hitMeHardBoiled:this.#T();break;case c.gameOptions:this.#_();break;case c.ping:this.#M();break;case c.switchTeam:this.#E();break;case c.changeCharacter:this.#O();break;case c.reload:this.#N();break;case c.explode:this.#L();break;case c.throwGrenade:this.#D();break;case c.spawnItem:this.#f();break;case c.melee:this.#A();break;case c.updateBalance:this.#G();break;case c.challengeCompleted:this.#$();break;case c.socketReady:this.#z();break;case c.gameJoined:this.#W();break;case c.gameAction:this.#R();break;case c.requestGameOptions:this.#B();break;case c.respawnDenied:this.#F();break;case c.expireUpgrade:case c.clientReady:break;case c.musicInfo:s.unPackLongString();break;default:console.error(`handlePacket: I got but did not handle a: ${Object.keys(c).find(o=>c[o]===i)} ${i}`),t&&console.error(`handlePacket: It may be a result of the ${t} command (${a}).`),n=!0;break}t=Object.keys(c).find(o=>c[o]===i),a=i,this.intents.includes(this.Intents.LOG_PACKETS)&&console.log(`[LOG_PACKETS] Packet ${t}: ${a}`)}}async checkChiknWinner(){const e=await k({cmd:"chicknWinnerReady",id:this.account.id,sessionId:this.account.sessionId});return typeof e=="string"?e:(this.account.cw.limit=e.limit,this.account.cw.atLimit=e.limit>=4,this.account.cw.secondsUntilPlay=(this.account.cw.atLimit?e.period:e.span)||0,this.account.cw.canPlayAgain=Date.now()+this.account.cw.secondsUntilPlay*1e3,this.account.cw)}async playChiknWinner(e=!0){if(this.account.cw.atLimit||this.account.cw.limit>j)return"hit_daily_limit";if(this.account.cw.canPlayAgain>Date.now()&&e)return"on_cooldown";const t=await k({cmd:"incentivizedVideoReward",firebaseId:this.account.firebaseId,id:this.account.id,sessionId:this.account.sessionId,token:null},this.proxy,`${this.protocol}://${this.instance}`);return typeof t=="string"?t:t.error?t.error=="RATELIMITED"||t.error=="RATELMITED"?(await this.checkChiknWinner(),"on_cooldown"):t.error=="SESSION_EXPIRED"?"session_expired":(console.error("Unknown Chikn Winner response",t),"unknown_error"):t.reward?(this.account.eggBalance+=t.reward.eggsGiven,t.reward.itemIds.forEach(a=>this.account.ownedItemIds.push(a)),await this.checkChiknWinner(),t.reward):(console.error("Unknown Chikn Winner response",t),"unknown_error")}async resetChiknWinner(){if(this.account.eggBalance<200)return"not_enough_eggs";if(!this.account.cw.atLimit)return"not_at_limit";const e=await k({cmd:"chwReset",sessionId:this.account.sessionId});return typeof e=="string"?e:e.result!=="SUCCESS"?(console.error("Unknown Chikn Winner reset response",e),"unknown_error"):(this.account.eggBalance-=200,await this.checkChiknWinner(),this.account.cw)}canSee(e){if(!this.intents.includes(this.Intents.PATHFINDING))throw new Error("You must have the PATHFINDING intent to use this method.");return this.pathing.nodeList.hasLineOfSight(this.me.position,e.position)}getBestTarget(e=()=>!0){const t=Object.values(this.players).filter(i=>i).filter(i=>i!==this.me).filter(i=>i.playing).filter(i=>i.hp>0).filter(i=>i.name!==this.me.name).filter(i=>this.me.team===0||i.team!==this.me.team).filter(i=>this.canSee(i)).filter(i=>!!e(i));let a=200,n=null;for(const i of t){const o=i.position.x-this.me.position.x,r=i.position.y-this.me.position.y,m=i.position.z-this.me.position.z,d=Math.sqrt(o*o+r*r+m*m);d<a&&(a=d,n=i)}return n}async refreshChallenges(){const e=await k({cmd:"challengeGetDaily",sessionId:this.account.sessionId,playerId:this.account.id},this.proxy,`${this.protocol}://${this.instance}`);return this.#i(e),this.account.challenges}async rerollChallenge(e){const t=await k({cmd:"challengeRerollSlot",sessionId:this.account.sessionId,slotId:e},this.proxy,`${this.protocol}://${this.instance}`);return this.#i(t),this.account.challenges}async claimChallenge(e){const t=await k({cmd:"challengeClaimReward",sessionId:this.account.sessionId,slotId:e},this.proxy,`${this.protocol}://${this.instance}`);return this.#i(t.challenges),{eggReward:t.reward,updatedChallenges:this.account.challenges}}async refreshBalance(){const e=await k({cmd:"checkBalance",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId},this.proxy,`${this.protocol}://${this.instance}`);return this.account.eggBalance=e.currentBalance,e.currentBalance}async redeemCode(e){const t=await k({cmd:"redeem",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,id:this.account.id,code:e},this.proxy,`${this.protocol}://${this.instance}`);return t.result==="SUCCESS"?(this.account.eggBalance=t.eggs_given,t.item_ids.forEach(a=>this.account.ownedItemIds.push(a)),{result:t,eggsGiven:t.eggs_given,itemIds:t.item_ids}):t}async claimURLReward(e){const t=await k({cmd:"urlRewardParams",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,reward:e},this.proxy,`${this.protocol}://${this.instance}`);return t.result==="SUCCESS"&&(this.account.eggBalance+=t.eggsGiven,t.itemIds.forEach(a=>this.account.ownedItemIds.push(a))),t}async claimSocialReward(e){const t=await k({cmd:"reward",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,rewardTag:e},this.proxy,`${this.protocol}://${this.instance}`);return t.result==="SUCCESS"&&(this.account.eggBalance+=t.eggsGiven,t.itemIds.forEach(a=>this.account.ownedItemIds.push(a))),t}async buyItem(e){const t=await k({cmd:"buy",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,itemId:e,save:!0},this.proxy,`${this.protocol}://${this.instance}`);return t.result==="SUCCESS"&&(this.account.eggBalance=t.currentBalance,this.account.ownedItemIds.push(t.itemId)),t}quit(e=!1,t=!1){this.state.quit||(this.intents.includes(this.Intents.PLAYER_HEALTH)&&clearInterval(this.healthIntervalId),clearInterval(this.updateIntervalId),this.game?.socket&&this.game.socket.close(),this.matchmaker&&this.matchmaker.close(),t||(this.#t=[]),this.#s=[],e||(delete this.account,delete this.game,delete this.me,delete this.players),this.state.quit=!0,this.emit("quit"))}}var gt=tt;export{tt as Bot,gt as default};
@@ -1,3 +1,3 @@
1
1
  /* eslint-disable */
2
2
 
3
- const e={swapWeapon:0,joinGame:1,spawnItem:3,observeGame:4,ping:5,bootPlayer:6,reportPlayer:10,switchTeam:13,changeCharacter:14,pause:15,gameOptions:16,gameAction:17,requestGameOptions:18,gameJoined:19,socketReady:20,addPlayer:21,removePlayer:22,fire:23,melee:24,throwGrenade:25,eventModifier:27,hitThem:28,hitMe:29,collectItem:30,chat:34,syncThem:35,die:37,beginShellStreak:38,endShellStreak:39,updateBalance:42,reload:43,respawn:44,respawnDenied:45,clientReady:47,requestRespawn:48,metaGameState:53,syncMe:54,explode:55,keepAlive:56,musicInfo:57,hitMeHardBoiled:58,challengeCompleted:60};export{e as CommCode};
3
+ const e={swapWeapon:0,joinGame:1,refreshGameState:2,spawnItem:3,observeGame:4,ping:5,bootPlayer:6,banPlayer:7,loginRequired:8,gameLocked:9,reportPlayer:10,switchTeam:13,changeCharacter:14,pause:15,gameOptions:16,gameAction:17,requestGameOptions:18,gameJoined:19,socketReady:20,addPlayer:21,removePlayer:22,fire:23,melee:24,throwGrenade:25,eventModifier:27,hitThem:28,hitMe:29,collectItem:30,challengeResetInGame:31,chat:34,syncThem:35,die:37,beginShellStreak:38,endShellStreak:39,updateBalance:42,reload:43,respawn:44,respawnDenied:45,clientReady:47,requestRespawn:48,switchTeamFail:51,expireUpgrade:52,metaGameState:53,syncMe:54,explode:55,keepAlive:56,musicInfo:57,hitMeHardBoiled:58,playerInfo:59,challengeCompleted:60};export{e as CommCode};
@@ -0,0 +1,2 @@
1
+ export declare function fetchMap(name: string, hash: string): Promise<Record<string, any>>;
2
+ export declare function initKotcZones(meshData: Array<{ x: number; y: number; z: number }>): Array<Array<{ x: number; y: number; z: number; zone: number }>>;
package/dist/util.js ADDED
@@ -0,0 +1,3 @@
1
+ /* eslint-disable */
2
+
3
+ import{IsBrowser as p}from"./constants.js";async function y(i,r){if(p)return await(await fetch(`https://esm.sh/gh/yolkorg/maps/maps/${i}.json?${r}`)).json();{const{existsSync:t,mkdirSync:a,readFileSync:l,writeFileSync:z}=await import("node:fs"),{join:o}=await import("node:path"),{homedir:s}=await import("node:os"),e=o(s(),".yolkbot"),n=o(e,"maps");t(e)||a(e),t(n)||a(n);const c=o(n,`${i}-${r}.json`);if(t(c))return JSON.parse(l(c,"utf-8"));const f=await(await fetch(`https://esm.sh/gh/yolkorg/maps/maps/${i}.json?${r}`)).json();return z(c,JSON.stringify(f,null,4),{flag:"w+"}),f}}function x(i){let r=0;const t={},a=[];for(const o of i)t[o.x]||(t[o.x]={}),t[o.x][o.y]||(t[o.x][o.y]={}),t[o.x][o.y][o.z]={zone:null};const l=[{x:-1,z:0},{x:1,z:0},{x:0,z:-1},{x:0,z:1}];function z(o,s,e){return t[o]&&t[o][s]&&t[o][s][e]?t[o][s][e]:null}for(const o of i)if(!t[o.x][o.y][o.z].zone){o.zone=++r,t[o.x][o.y][o.z].zone=o.zone;const s=[o];let e;do{e=0;for(const n of i)if(!t[n.x][n.y][n.z].zone)for(const c of l){const f=z(n.x+c.x,n.y,n.z+c.z);if(f&&f.zone==o.zone){e++,n.zone=o.zone,t[n.x][n.y][n.z].zone=o.zone,s.push(n);break}}}while(e>0);a.push(s)}return a}export{y as fetchMap,x as initKotcZones};
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "yolkbot",
3
3
  "description": "create a shell shockers bot in under 10 lines.",
4
- "version": "0.1.4-alpha.27",
4
+ "version": "0.1.4-alpha.29",
5
5
  "keywords": [
6
6
  "shell shockers",
7
7
  "shellshock.io",
@@ -44,6 +44,10 @@
44
44
  "import": "./dist/matchmaker.js",
45
45
  "types": "./dist/types/matchmaker.d.ts"
46
46
  },
47
+ "./util": {
48
+ "import": "./dist/util.js",
49
+ "types": "./dist/types/util.d.ts"
50
+ },
47
51
  "./pathing/*": "./dist/pathing/*.js",
48
52
  "./pathing/*.js": "./dist/pathing/*.js",
49
53
  "./bot": {