yolkbot 1.1.0 → 1.1.2
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/browser/build/global.js +2 -2
- package/browser/build/module.js +2 -2
- package/dist/bot.js +1 -1
- package/dist/matchmaker.js +1 -1
- package/dist/types/bot.d.ts +2 -1
- package/dist/types/matchmaker.d.ts +1 -0
- package/dist/wasm/bytes.js +1 -1
- package/dist/wasm/imports.js +1 -1
- package/package.json +1 -1
package/dist/bot.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
|
|
3
|
-
import Z from"./api.js";import s from"./comm/CommIn.js";import f from"./comm/CommOut.js";import W from"./constants/CloseCode.js";import c from"./constants/CommCode.js";import U from"./bot/GamePlayer.js";import $ from"./matchmaker.js";import q from"./socket.js";import{ChiknWinnerDailyLimit as Y,CollectType as T,CoopState as y,findItemById as g,FramesBetweenSyncs as w,GameAction as E,GameMode as p,GameOptionFlag as X,GunList as J,ItemType as V,Movement as b,PlayType as F,ProxiesEnabled as Q,ShellStreak as u,StateBufferSize as S}from"./constants/index.js";import G from"./dispatches/LookAtPosDispatch.js";import O from"./dispatches/MovementDispatch.js";import{NodeList as tt}from"./pathing/mapnode.js";import{coords as et}from"./wasm/wrapper.js";import{fetchMap as st,initKotcZones as at}from"./util.js";import{Challenges as it}from"./constants/challenges.js";import{Maps as R}from"./constants/maps.js";import{Regions as _}from"./constants/regions.js";const M=Object.fromEntries(Object.entries(y).map(([k,t])=>[t,k.toLowerCase()])),A=Object.fromEntries(Object.entries(p).map(([k,t])=>[t,k])),L=Object.fromEntries(Object.entries(X).map(([k,t])=>[k[0].toLowerCase()+k.slice(1),t])),N={CHALLENGES:1,STATS:2,PATHFINDING:3,PING:5,COSMETIC_DATA:6,PLAYER_HEALTH:7,PACKET_HOOK:8,LOG_PACKETS:10,NO_LOGIN:11,DEBUG_BUFFER:12,DEBUG_BEST_TARGET:14,NO_AFK_KICK:16,LOAD_MAP:17,OBSERVE_GAME:18,NO_REGION_CHECK:19},v=(k,t)=>(k%t+t)%t;class nt{static Intents=N;Intents=N;#e=[];#t={};#i=[];#s;#n;constructor(t={}){t.proxy&&!Q&&this.processError("proxies do not work and hence are not supported in the browser"),this.intents=t.intents||[],this.intents.includes(this.Intents.COSMETIC_DATA)&&(g(1001)||this.processError("you cannot use the COSMETIC_DATA intent inside of the singlefile browser bundles")),this.instance=t.instance||"shellshock.io",this.protocol=t.protocol||"wss",this.proxy=t.proxy||"",this.httpProxy=t.httpProxy||"",this.state={name:"yolkbot",weaponIdx:0,inGame:!1,chatLines:0,yaw:0,pitch:0,controlKeys:0,reloading:!1,swappingGun:!1,usingMelee:!1,stateIdx:0,serverStateIdx:0,shotsFired:0,buffer:[],left:!1},this.players={},this.me=new U({}),this.game={raw:{},code:"",socket:null,gameModeId:0,gameMode:A[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.#n=this.game,this.account={id:0,firebase:{idToken:"",refreshToken:"",expiresIn:"3600",localId:""},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,emailVerified:!1,isAged:!1,eggBalance:0,adminRoles:0,rawLoginData:{},isDoubleEggWeeknd:()=>{const e=new Date().getUTCDay(),a=new Date().getUTCHours();return e>=5&&a>=20||e===6||e===0}},this.#s=this.account,this.matchmaker=null,this.api=new Z({instance:this.instance,protocol:this.protocol,proxy:this.proxy,httpProxy:this.httpProxy,maxRetries:t?.apiMaxRetries}),this.ping=0,this.lastPingTime=-1,this.lastDeathTime=-1,this.lastUpdateTick=0,this.pathing={nodeList:null,followingPath:!1,activePath:null,activeNode:null,activeNodeIdx:0},this.hasQuit=!1,this.intents.includes(this.Intents.NO_AFK_KICK)&&(this.afkKickInterval=0)}dispatch(t){return t.validate(this)?(t.check(this)?t.execute(this):this.#e.push(t),!0):!1}async createAccount(t,e){this.account=this.#s,this.account.email=t,this.account.password=e;const a=await this.api.createAccount(t,e);return this.processLoginData(a)}async login(t,e){this.account=this.#s,this.account.email=t,this.account.password=e;const a=await this.api.loginWithCredentials(t,e);return this.processLoginData(a)}async loginWithRefreshToken(t){this.account=this.#s;const e=await this.api.loginWithRefreshToken(t);return this.processLoginData(e)}async loginAnonymously(){this.account=this.#s;const t=await this.api.loginAnonymously();return this.processLoginData(t)}processLoginData(t){return typeof t!="object"?(this.emit("authFail",t),t):t.banRemaining?(this.emit("banned",t.banRemaining),"account_banned"):t.playerOutput?(this.account.firebase=t.firebase||{},t=t.playerOutput,this.account.rawLoginData=t,this.account.adminRoles=t.adminRoles||0,this.account.eggBalance=t.currentBalance,this.account.emailVerified=t.emailVerified,this.account.firebaseId=t.firebaseId,this.account.id=t.id,this.account.isAged=new Date(t.dateCreated).getTime()<17145468e5,this.account.loadout=t.loadout,this.account.ownedItemIds=t.ownedItemIds,this.account.session=t.session,this.account.sessionId=t.sessionId,this.account.vip=t.active_sub==="IsVIP",this.intents.includes(this.Intents.STATS)&&(this.account.stats={lifetime:t.statsLifetime,monthly:t.statsCurrent}),this.intents.includes(this.Intents.CHALLENGES)&&this.#a(t.challenges),this.emit("authSuccess",this.account),this.account):(this.emit("authFail",t),t)}#a(t){this.account.challenges=[];for(const e of t){const a=it.find(i=>i.id===e.challengeId);a&&(delete e.playerId,this.account.challenges.push({raw:{challengeInfo:a,challengeData:e},id:e.challengeId,name:a.loc.title,desc:a.loc.desc,rewardEggs:a.reward,isRerolled:!!e.reset,isClaimed:!!e.claimed,isCompleted:!!e.completed,progressNum:e.progress,goalNum:a.goal}))}}async initMatchmaker(){if(!this.account.sessionId&&!this.intents.includes(this.Intents.NO_LOGIN)){const t=await this.loginAnonymously();if(typeof t!="object")return t}return this.matchmaker||(this.matchmaker=new $({sessionId:this.account.sessionId,proxy:this.proxy,instance:this.instance,protocol:this.protocol,noLogin:this.intents.includes(this.Intents.NO_LOGIN),api:this.api}),this.matchmaker.on("authFail",t=>this.emit("authFail",t)),this.matchmaker.on("error",t=>this.processError(t)),await this.matchmaker.getRegions()),!0}async findPublicGame(t,e){return typeof t!="string"?"no_region_passed":!_.find(i=>i.id===t)&&!this.intents.includes(this.Intents.NO_REGION_CHECK)?"invalid_region_passed":typeof e!="number"?"no_mode_passed":Object.values(p).indexOf(e)===-1?"invalid_mode_passed":await this.initMatchmaker()?await new Promise(i=>{const o=n=>{n.command==="gameFound"&&(this.matchmaker.off("msg",o),i(n))};this.matchmaker.on("msg",o),this.matchmaker.send({command:"findGame",region:t,playType:F.JoinPublic,gameType:e,sessionId:this.sessionId})}):"matchmaker_init_fail"}async createPrivateGame(t,e,a){if(typeof t!="string")return"no_region_passed";if(!_.find(n=>n.id===t)&&!this.intents.includes(this.Intents.NO_REGION_CHECK))return"invalid_region_passed";if(typeof e!="number")return"no_mode_passed";if(Object.values(p).indexOf(e)===-1)return"invalid_mode_passed";if(typeof a!="string")return"no_map_passed";const i=R.findIndex(n=>n.name.toLowerCase()===a.toLowerCase());return i===-1?"invalid_map_passed":(await this.matchmaker.waitForConnect(),await new Promise(n=>{const r=m=>{m.command==="gameFound"&&(this.matchmaker.off("msg",r),n(m))};this.matchmaker.on("msg",r),this.matchmaker.send({command:"findGame",region:t,playType:F.CreatePrivate,gameType:e,sessionId:this.account.sessionId,noobLobby:!1,map:i})}))}async join(t,e){if(this.state.name=t||"yolkbot",typeof e=="string"){if(e.includes("#")&&(e=e.split("#")[1]),!await this.initMatchmaker())return"matchmakerInitFail";await this.matchmaker.waitForConnect();const i=await new Promise(o=>{const n=r=>{if(r.command==="gameFound"&&(this.matchmaker.off("msg",n),this.game.raw=r,this.game.code=r.id,o(r.id)),r.error&&r.error==="gameNotFound")return this.processError(`game "${e}" not found, it may have expired.`),this.leave(),"gameNotFound"};this.matchmaker.on("msg",n),this.matchmaker.send({command:"joinGame",id:e,observe:!1,sessionId:this.account.sessionId})});if(i==="matchmakerInitFail")return this.processError("failed to create matchmaker, you may be ratelimited (try a vpn?)");if(i==="gameNotFound")return this.processError("game not found, it may have expired or been deleted");if(!this.game.raw.id)return this.processError("an internal error occured while joining the game, please report this to developers")}if(typeof e=="object"){if(this.account.id===0&&await this.loginAnonymously(),this.game.raw=e,this.game.code=this.game.raw.id,!this.game.raw.id)return this.processError("invalid game object passed to join (missing id)");if(!this.game.raw.subdomain)return this.processError("invalid game object passed to join (missing subdomain)");if(!this.game.raw.uuid)return this.processError("invalid game object passed to join (missing uuid)")}const a=async()=>{try{const i=this.instance.startsWith("localhost:")?this.instance:`${this.game.raw.subdomain}.${this.instance}`;this.game.socket=new q(`${this.protocol}://${i}/game/${this.game.raw.id}`,this.proxy),this.game.socket.onerror=async o=>(this.processError(o),await new Promise(n=>setTimeout(n,100)),await a())}catch{await new Promise(i=>setTimeout(i,100)),await a()}};await a(),this.game.socket.binaryType="arraybuffer",this.game.socket.onopen=()=>this.game.socket.onerror=null,this.game.socket.onmessage=i=>this.processPacket(i.data),this.game.socket.onclose=i=>{this.state.left?this.state.left=!1:(this.emit("close",i.code),this.leave(-1))}}#o(){if(Object.entries(this.me.position).map(e=>Math.floor(e[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 O(0));else{let e;this.pathing.activeNodeIdx<this.pathing.activePath.length-1?(e=this.pathing.activePath[this.pathing.activeNodeIdx+1].flatCenter(),this.dispatch(new G(e))):(e=this.pathing.activePath[this.pathing.activeNodeIdx].flatCenter(),this.dispatch(new G(e)));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.state.controlKeys&b.Forward||this.dispatch(new O(b.Forward))}}update(){if(!this.hasQuit){if(this.pathing.followingPath&&this.intents.includes(this.Intents.PATHFINDING)&&this.#o(),this.#e.length>0)for(let t=0;t<this.#e.length;t++){const e=this.#e[t];e.check(this)&&(e.execute(this),this.#e.splice(t,1))}if(this.state.chatLines=Math.max(0,this.state.chatLines-1/(30*4)),this.me.playing){const t=this.state.stateIdx;if(this.intents.includes(this.Intents.DEBUG_BUFFER)&&(console.log("setting buffer for idx",t),console.log("checking...shotsFired",this.state.shotsFired)),this.me.jumping=!!(this.state.controlKeys&b.Jump),this.state.buffer[t]={controlKeys:this.state.controlKeys,yaw:this.state.yaw,pitch:this.state.pitch,shotsFired:this.state.shotsFired},this.state.shotsFired=0,this.lastUpdateTick>=2){this.emit("tick");const e=new f;e.packInt8(c.syncMe),e.packInt8(this.state.stateIdx),e.packInt8(this.state.serverStateIdx);const a=v(this.state.stateIdx-w+1,S);for(let i=0;i<w;i++){const o=v(a+i,S);this.intents.includes(this.Intents.DEBUG_BUFFER)&&console.log("going with",this.state.stateIdx,a,o,this.state.buffer[o]),e.packInt8(this.state.buffer[o]?.controlKeys||0),e.packInt8(this.state.buffer[o]?.shotsFired||0);const n=this.state.buffer[o]?.yaw||this.state.yaw,r=this.state.buffer[o]?.pitch||this.state.pitch,m=et(n,r);e.packString(m),e.packInt8(100)}e.send(this.game.socket),this.state.buffer=[],this.lastUpdateTick=0}else this.lastUpdateTick++;this.state.stateIdx=v(this.state.stateIdx+1,S)}if(this.intents.includes(this.Intents.PLAYER_HEALTH))for(const t of Object.values(this.players)){if(t.playing&&t.hp>0){const e=.1*(this.game.isPrivate?this.game.options.healthRegen:1);t.streakRewards.includes(u.OverHeal)?t.hp=Math.max(100,t.hp-e):t.hp=Math.min(100,t.hp+e)}t.spawnShield>0&&(t.spawnShield-=6)}}}on(t,e){Object.keys(this.#t).includes(t)?this.#t[t].push(e):this.#t[t]=[e]}once(t,e){const a=(...i)=>{e(...i),this.off(t,a)};this.on(t,a)}onAny(t){this.#i.push(t)}off(t,e){e?this.#t[t]=this.#t[t].filter(a=>a!==e):this.#t[t]=[]}emit(t,...e){if(!this.hasQuit){if(this.#t[t])for(const a of this.#t[t])a(...e);for(const a of this.#i)a(t,...e)}}#c(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=s.unPackString().valueOf(),i=this.players[t];this.emit("chat",i,a,e)}#r(){const t=s.unPackInt8U(),e=this.intents.includes(this.Intents.COSMETIC_DATA),a={id:t,uniqueId:s.unPackString(),name:s.unPackString(),safeName:s.unPackString(),charClass:s.unPackInt8U(),team:s.unPackInt8U(),primaryWeaponItem:e?g(s.unPackInt16U()):s.unPackInt16U(),secondaryWeaponItem:e?g(s.unPackInt16U()):s.unPackInt16U(),shellColor:s.unPackInt8U(),hatItem:e?g(s.unPackInt16U()):s.unPackInt16U(),stampItem:e?g(s.unPackInt16U()):s.unPackInt16U(),stampPosX:s.unPackInt8(),stampPosY:s.unPackInt8(),grenadeItem:e?g(s.unPackInt16U()):s.unPackInt16U(),meleeItem:e?g(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(),bestStreak: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()};this.game.mapIdx=s.unPackInt8U(),this.game.isPrivate=s.unPackInt8U()===1,this.game.gameModeId=s.unPackInt8U();const i=new U(a,this.game.gameMode===p.KOTC?this.game.activeZone:null);this.players[a.id]||(this.players[a.id]=i),this.emit("playerJoin",i),this.me.id===a.id&&(this.me=i,this.emit("botJoin",this.me))}#h(){const t=s.unPackInt8U(),e=s.unPackInt16U(),a=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackFloat(),n=s.unPackInt8U(),r=s.unPackInt8U(),m=s.unPackInt8U(),d=s.unPackInt8U(),I=s.unPackInt8U(),h=this.players[t];h&&(h.playing=!0,h.randomSeed=e,h.weapons[0]&&h.weapons[0].ammo&&(h.weapons[0].ammo.rounds=n),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:i,z:o},h.spawnShield=120,this.emit("playerRespawn",h))}#l(){const t=s.unPackInt8U(),e=s.unPackFloat(),a=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackInt8U(),n=this.players[t];if(!n||n.id===this.me.id){for(let d=0;d<w;d++)s.unPackInt8U(),s.unPackRadU(),s.unPackRad(),s.unPackInt8U();return}for(let d=0;d<w;d++)s.unPackInt8U()&b.Jump?n.jumping=!0:n.jumping=!1,n.view.yaw=s.unPackRadU(),n.view.pitch=s.unPackRad(),s.unPackInt8U();const r=n.position.x!==e||n.position.y!==a||n.position.z!==i||n.climbing!==o,m=r?{...n.position}:null;if(n.position.x!==e&&(n.position.x=e),n.position.z!==i&&(n.position.z=i),(!n.jumping||Math.abs(n.position.y-a)>.5&&n.position.y!==a)&&(n.position.y=a),n.climbing!==o&&(n.climbing=o),r&&(this.emit("playerMove",n,m,n.position),this.game.gameModeId===p.KOTC)){const d=this.game.activeZone;if(!d){n.inKotcZone&&(n.inKotcZone=!1,this.emit("playerLeaveZone",n));return}const I=!!n.inKotcZone;n.updateKotcZone(d),!n.inKotcZone&&I?(n.inKotcZone=!1,this.emit("playerLeaveZone",n)):n.inKotcZone&&!I&&(n.inKotcZone=!0,this.emit("playerEnterZone",n))}}#m(){const t=s.unPackInt8U(),e=this.players[t];e&&(e.playing=!1,e.streakRewards&&(e.streakRewards=[]),this.emit("playerPause",e),e.inKotcZone&&(e.inKotcZone=!1,this.emit("playerLeaveZone",e)))}#u(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];a&&(a.activeGun=e,this.emit("playerSwapWeapon",a,e))}#d(){const t=s.unPackInt8U(),e=s.unPackInt8U();s.unPackInt8U(),s.unPackInt8U(),s.unPackInt8U();const a=this.players[t],i=this.players[e];a&&(a.id===this.me.id&&(this.lastDeathTime=Date.now()),a.playing=!1,a.streak=0,a.hp=100,a.spawnShield=0,a.stats.totalDeaths++,a.inKotcZone=!1,this.emit("playerLeaveZone",a)),i&&(i.streak++,i.stats.totalKills++,i.streak>i.stats.bestStreak&&(i.stats.bestStreak=i.streak)),this.emit("playerDeath",a,i)}#p(){const t=s.unPackInt8U(),e={posX:s.unPackFloat(),posY:s.unPackFloat(),posZ:s.unPackFloat(),dirX:s.unPackFloat(),dirY:s.unPackFloat(),dirZ:s.unPackFloat()},a=this.players[t];if(!a)return;const i=a.weapons[a.activeGun];i&&i.ammo&&(i.ammo.rounds--,this.emit("playerFire",a,i,e))}#g(){const t=s.unPackInt16U(),e=s.unPackInt8U(),a=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackFloat();this.game.collectables[e].push({id:t,x:a,y:i,z:o}),this.emit("spawnItem",e,{x:a,y:i,z:o})}#k(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=s.unPackInt8U(),i=s.unPackInt16U(),o=this.players[t];if(this.game.collectables[e]=this.game.collectables[e].filter(n=>n.id!==i),e===T.Ammo){const n=o.weapons[a];n&&n.ammo&&(n.ammo.store=Math.min(n.ammo.storeMax,n.ammo.store+n.ammo.pickup),this.emit("collectAmmo",o,n))}e===T.Grenade&&(o.grenades++,o.grenades>3&&(o.grenades=3),this.emit("collectGrenade",o))}#f(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];if(!a)return;const i=a.hp;a.hp=e,this.emit("playerDamage",a,i,a.hp)}#I(){const t=s.unPackInt8U();s.unPackFloat(),s.unPackFloat();const e=this.me.hp;this.me.hp=t,this.emit("playerDamage",this.me,e,this.me.hp)}#P(){const t=s.unPackInt8U(),e=this.players[t];s.unPackInt8U();const a=s.unPackInt8U(),i=s.unPackFloat(),o=s.unPackFloat(),n=s.unPackFloat();if(this.me.climbing=!!s.unPackInt8U(),s.unPackInt8U(),s.unPackInt8U(),!e)return;this.state.serverStateIdx=a;const r=e.position.x,m=e.position.y,d=e.position.z;e.position.x=i,e.position.y=o,e.position.z=n,(r!==i||m!==o||d!==n)&&this.emit("playerMove",e,{x:r,y:m,z:d},{x:i,y:o,z:n})}#y(){const t=new f;t.packInt8(c.eventModifier),t.send(this.game.socket)}#w(){const t=s.unPackInt8U(),e={...this.players[t]};delete this.players[t.toString()],this.emit("playerLeave",e)}#b(){if(this.game.gameModeId===p.Spatula){const t={...this.game};this.game.teamScore[1]=s.unPackInt16U(),this.game.teamScore[2]=s.unPackInt16U();const e={x:s.unPackFloat(),y:s.unPackFloat(),z:s.unPackFloat()},a=s.unPackInt8U(),i=s.unPackInt8U();this.game.spatula={coords:e,controlledBy:a,controlledByTeam:i},this.emit("gameStateChange",t,this.game)}else if(this.game.gameModeId===p.KOTC){const t={...this.game};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.game.activeZone&&Object.values(this.players).forEach(e=>e.updateKotcZone(this.game.activeZone)),this.game.numCapturing<=0&&Object.values(this.players).forEach(e=>{e.inKotcZone=!1,this.emit("playerLeaveZone",e)}),this.emit("gameStateChange",t,this.game)}else this.game.gameModeId===p.Team&&(this.game.teamScore[1]=s.unPackInt16U(),this.game.teamScore[2]=s.unPackInt16U());this.game.gameModeId!==p.Spatula&&delete this.game.spatula,this.game.gameModeId!==p.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===p.FFA&&delete this.game.teamScore}#U(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];switch(e){case u.HardBoiled:t===this.me.id&&(this.me.shieldHp=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,e)}#S(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];[u.EggBreaker,u.OverHeal,u.DoubleEggs,u.MiniEgg].includes(e)&&a.streakRewards.includes(e)&&(a.streakRewards=a.streakRewards.filter(o=>o!==e)),this.emit("playerEndStreak",a,e)}#v(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=s.unPackFloat(),i=s.unPackFloat();this.me.shieldHp=t,this.me.hp=e,this.me.shieldHp<=0?(this.me.streakRewards=this.me.streakRewards.filter(o=>o!==u.HardBoiled),this.emit("selfShieldLost",this.me.hp,{dx:a,dz:i})):this.emit("selfShieldHit",this.me.shieldHp,this.me.hp,{dx:a,dz:i})}#C(){const t={...this.game.options};let e=s.unPackInt8U(),a=s.unPackInt8U(),i=s.unPackInt8U();(e<1||e>4)&&(e=4),(a<0||a>8)&&(a=4),i>16&&(i=4),this.game.options.gravity=e/4,this.game.options.damage=a/4,this.game.options.healthRegen=i/4;const o=s.unPackInt8U();Object.keys(L).forEach(n=>{const r=o&L[n]?1:0;this.game.options[n]=r}),this.game.options.weaponsDisabled=Array.from({length:7},()=>s.unPackInt8U()===1),this.game.options.mustUseSecondary=this.game.options.weaponsDisabled.every(n=>n),this.emit("gameOptionsChange",t,this.game.options)}#x(){const t=s.unPackInt8U();t===E.Pause&&(this.emit("gameForcePause"),setTimeout(()=>this.me.playing=!1,3e3)),t===E.Reset&&(Object.values(this.players).forEach(e=>e.streak=0),this.game.gameModeId!==p.FFA&&(this.game.teamScore=[0,0,0]),this.game.gameModeId===p.Spatula&&(this.game.spatula.controlledBy=0,this.game.spatula.controlledByTeam=0,this.game.spatula.coords={x:0,y:0,z:0}),this.game.gameModeId===p.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"))}#T(){if(!this.intents.includes(this.Intents.PING))return;const t=this.ping;this.ping=Date.now()-this.lastPingTime,this.emit("pingUpdate",t,this.ping),setTimeout(()=>{const e=new f;e.packInt8(c.ping),e.send(this.game.socket),this.lastPingTime=Date.now()},1e3)}#E(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];if(!a)return;const i=a.team;a.team=e,a.streak=0,this.emit("playerSwitchTeam",a,i,e)}#F(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=s.unPackInt16U(),i=s.unPackInt16U(),o=s.unPackInt8U(),n=s.unPackInt16U(),r=s.unPackInt16U(),m=s.unPackInt16U(),d=s.unPackInt16U(),I=s.unPackInt8(),h=s.unPackInt8(),P=this.intents.includes(this.Intents.COSMETIC_DATA),B=P?g(a):a,D=P?g(i):i,K=P?g(n):n,H=P?g(r):r,j=P?g(m):m,z=P?g(d):d,l=this.players[t];if(l){const C={...l.character},x=l.selectedGun;l.character.eggColor=o,l.character.primaryGun=B,l.character.secondaryGun=D,l.character.stamp=H,l.character.hat=K,l.character.grenade=j,l.character.melee=z,l.character.stampPos.x=I,l.character.stampPos.y=h,l.selectedGun=e,l.weapons[0]=new J[e],x!==l.selectedGun&&this.emit("playerChangeGun",l,x,l.selectedGun),C!==l.character&&this.emit("playerChangeCharacter",l,C,l.character)}}#G(){const t=s.unPackInt32U(),e=this.account.eggBalance;this.account.eggBalance=t,this.emit("balanceUpdate",e,t)}#O(){this.me.playing=!1,this.emit("respawnDenied")}#R(){const t=s.unPackInt8U(),e=this.players[t];e&&this.emit("playerMelee",e)}#_(){const t=s.unPackInt8U(),e=this.players[t];if(!e)return;const a=e.weapons[e.activeGun];if(a.ammo){const i=Math.min(Math.min(a.ammo.capacity,a.ammo.reload)-a.ammo.rounds,a.ammo.store);a.ammo.rounds+=i,a.ammo.store-=i}this.emit("playerReload",e,a)}updateGameOptions(){const t=new f;t.packInt8(c.gameOptions),t.packInt8(this.game.options.gravity*4),t.packInt8(this.game.options.damage*4),t.packInt8(this.game.options.healthRegen*4);const e=(this.game.options.locked?1:0)|(this.game.options.noTeamChange?2:0)|(this.game.options.noTeamShuffle?4:0);t.packInt8(e),this.game.options.weaponsDisabled.forEach(a=>{t.packInt8(a?1:0)}),t.send(this.game.socket)}#M(){this.game.isPrivate=!0,this.updateGameOptions()}#A(){const t=s.unPackInt8U();let e=s.unPackInt16U();const a=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackFloat(),n=s.unPackInt8U(),r=s.unPackFloat();this.intents.includes(this.Intents.COSMETIC_DATA)&&(e=g(e)),t===V.Grenade?this.emit("grenadeExplode",e,{x:a,y:i,z:o},n,r):this.emit("rocketHit",{x:a,y:i,z:o},n,r)}#L(){const t=s.unPackInt8U(),e=s.unPackFloat(),a=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackFloat(),n=s.unPackFloat(),r=s.unPackFloat(),m=this.players[t];m&&(m.grenades--,this.emit("playerThrowGrenade",m,{x:e,y:a,z:i},{x:o,y:n,z:r}))}#N(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];if(!a)return;if(!this.intents.includes(this.Intents.CHALLENGES))return this.emit("challengeComplete",a,e);const i=this.account.challenges.find(o=>o.id===e);this.emit("challengeComplete",a,i),a.id===this.me.id&&this.refreshChallenges()}#B(){const t=new f;t.packInt8(this.intents.includes(this.Intents.OBSERVE_GAME)?c.observeGame:c.joinGame),t.packString(this.state.name),t.packString(this.game.raw.uuid),t.packInt8(0),t.packInt8(this.state.weaponIdx||this.account?.loadout?.classIdx||0),t.packInt32(this.account.session),t.packString(this.account.firebaseId),t.packString(this.account.sessionId),t.send(this.game.socket)}async#D(){if(this.me.id=s.unPackInt8U(),this.me.team=s.unPackInt8U(),this.game.gameModeId=s.unPackInt8U(),this.game.gameMode=A[this.game.gameModeId],this.game.mapIdx=s.unPackInt8U(),this.game.map=R[this.game.mapIdx],this.game.playerLimit=s.unPackInt8U(),this.game.isGameOwner=s.unPackInt8U()===1,this.game.isPrivate=s.unPackInt8U()===1||this.game.isGameOwner,s.unPackInt8U(),this.intents.includes(this.Intents.LOAD_MAP)||this.intents.includes(this.Intents.PATHFINDING)){if(this.game.map.raw=await st(this.game.map.filename,this.game.map.hash),this.emit("mapLoad",this.game.map.raw),this.game.gameModeId===p.KOTC){const e=this.game.map.raw.data["DYNAMIC.capture-zone.none"];e?(this.game.map.zones=at(e),this.game.activeZone||(this.game.activeZone=this.game.map.zones[this.game.zoneNumber-1])):delete this.game.map.zones}this.intents.includes(this.Intents.PATHFINDING)&&(this.pathing.nodeList=new tt(this.game.map.raw))}this.state.inGame=!0,this.lastDeathTime=Date.now();const t=new f;if(t.packInt8(c.clientReady),t.send(this.game.socket),this.updateIntervalId=setInterval(()=>this.update(),100/3),this.intents.includes(this.Intents.PING)){this.lastPingTime=Date.now();const e=new f;e.packInt8(c.ping),e.send(this.game.socket)}this.afkKickInterval=setInterval(()=>{if(this.state.inGame&&!this.me.playing&&Date.now()-this.lastDeathTime>=15e3){const e=new f;e.packInt8(c.keepAlive),e.send(this.game.socket)}},15e3),this.emit("gameReady")}#K(){const t=s.unPackInt8U(),e=s.unPackString(128),a=s.unPackString(32);if(!this.players[t])return;const i=this.players[t];i.admin={ip:a,dbId:e},this.emit("playerInfo",i,a,e)}processPacket(t){s.init(t),this.intents.includes(this.Intents.PACKET_HOOK)&&this.emit("packet",t);let e=0,a=0,i=!1;for(;s.isMoreDataAvailable()&&!i;){const o=s.unPackInt8U();switch(o){case c.syncThem:this.#l();break;case c.fire:this.#p();break;case c.hitThem:this.#f();break;case c.syncMe:this.#P();break;case c.hitMe:this.#I();break;case c.swapWeapon:this.#u();break;case c.collectItem:this.#k();break;case c.respawn:this.#h();break;case c.die:this.#d();break;case c.pause:this.#m();break;case c.chat:this.#c();break;case c.addPlayer:this.#r();break;case c.removePlayer:this.#w();break;case c.eventModifier:this.#y();break;case c.metaGameState:this.#b();break;case c.beginShellStreak:this.#U();break;case c.endShellStreak:this.#S();break;case c.hitMeHardBoiled:this.#v();break;case c.gameOptions:this.#C();break;case c.ping:this.#T();break;case c.switchTeam:this.#E();break;case c.changeCharacter:this.#F();break;case c.reload:this.#_();break;case c.explode:this.#A();break;case c.throwGrenade:this.#L();break;case c.spawnItem:this.#g();break;case c.melee:this.#R();break;case c.updateBalance:this.#G();break;case c.challengeCompleted:this.#N();break;case c.socketReady:this.#B();break;case c.gameJoined:this.#D();break;case c.gameAction:this.#x();break;case c.requestGameOptions:this.#M();break;case c.respawnDenied:this.#O();break;case c.playerInfo:this.#K();break;case c.expireUpgrade:case c.clientReady:break;case c.musicInfo:s.unPackLongString();break;default:console.error(`processPacket: I got but couldn't identify a: ${Object.keys(c).find(n=>c[n]===o)} ${o}`),e&&console.error(`processPacket: It may be a result of the ${e} command (${a}).`),i=!0;break}e=Object.keys(c).find(n=>c[n]===o),a=o,this.intents.includes(this.Intents.LOG_PACKETS)&&console.log(`[LOG_PACKETS] Packet ${e}: ${a}`)}}async checkChiknWinner(){const t=await this.api.queryServices({cmd:"chicknWinnerReady",id:this.account.id,sessionId:this.account.sessionId});return typeof t=="string"?t:(this.account.cw.limit=t.limit,this.account.cw.atLimit=t.limit>=4,this.account.cw.secondsUntilPlay=(this.account.cw.atLimit?t.period:t.span)||0,this.account.cw.canPlayAgain=Date.now()+this.account.cw.secondsUntilPlay*1e3,this.account.cw)}async playChiknWinner(t=!0){if(this.account.cw.atLimit||this.account.cw.limit>Y)return"hit_daily_limit";if(this.account.cw.canPlayAgain>Date.now()&&t)return"on_cooldown";const e=await this.api.queryServices({cmd:"incentivizedVideoReward",firebaseId:this.account.firebaseId,id:this.account.id,sessionId:this.account.sessionId,token:null});return typeof e=="string"?e:e.error?e.error==="RATELIMITED"||e.error==="RATELMITED"?(await this.checkChiknWinner(),"on_cooldown"):e.error==="SESSION_EXPIRED"?"session_expired":(console.error("Unknown Chikn Winner response, report this on Github:",e),"unknown_error"):e.reward?(this.account.eggBalance+=e.reward.eggsGiven,e.reward.itemIds.forEach(a=>this.account.ownedItemIds.push(a)),await this.checkChiknWinner(),e.reward):(console.error("Unknown Chikn Winner response, report this on Github:",e),"unknown_error")}async resetChiknWinner(){if(this.account.eggBalance<200)return"not_enough_eggs";if(!this.account.cw.atLimit)return"not_at_limit";const t=await this.api.queryServices({cmd:"chwReset",sessionId:this.account.sessionId});return typeof t=="string"?t:t.result!=="SUCCESS"?(console.error("Unknown Chikn Winner reset response, report this on Github:",t),"unknown_error"):(this.account.eggBalance-=200,await this.checkChiknWinner(),this.account.cw)}canSee(t){return this.intents.includes(this.Intents.PATHFINDING)?this.pathing.nodeList.hasLineOfSight(this.me.position,t.position):this.processError("You must have the PATHFINDING intent to use this method.")}getBestTarget(t=()=>!0){const a=Object.values(this.players).filter(o=>o?.playing).filter(o=>o.hp>0).filter(o=>o.id!==this.me.id).filter(o=>this.me.team===0||o.team!==this.me.team).filter(o=>!!t(o)).map(o=>({player:o,distance:Math.sqrt(Math.pow(o.position.x-this.me.position.x,2)+Math.pow(o.position.y-this.me.position.y,2)+Math.pow(o.position.z-this.me.position.z,2))})).sort((o,n)=>o.distance-n.distance);if(!a.length)return this.intents.includes(this.Intents.DEBUG_BEST_TARGET)&&console.log("no targets found"),null;const i=a.find(o=>this.canSee(o.player));return this.intents.includes(this.Intents.DEBUG_BEST_TARGET)&&(console.log("detected ",a.length,"targets"),console.log("closest target: ",a[0].player.name),console.log("all targets (ordered): ",a.map(o=>o.player.name)),console.log("found LoS player?",!!i),i&&console.log("closest LoS player: ",i.player.name)),i?{player:i.player,inLoS:!0}:{player:a[0].player,inLoS:!1}}async refreshChallenges(){const t=await this.api.queryServices({cmd:"challengeGetDaily",sessionId:this.account.sessionId,playerId:this.account.id});return this.#a(t),this.account.challenges}async rerollChallenge(t){const e=await this.api.queryServices({cmd:"challengeRerollSlot",sessionId:this.account.sessionId,slotId:t});return this.#a(e),this.account.challenges}async claimChallenge(t){const e=await this.api.queryServices({cmd:"challengeClaimReward",sessionId:this.account.sessionId,slotId:t});return this.#a(e.challenges),e.reward>0&&(this.account.eggBalance+=e.reward),{eggReward:e.reward,updatedChallenges:this.account.challenges}}async refreshBalance(){const t=await this.api.queryServices({cmd:"checkBalance",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId});return this.account.eggBalance=t.currentBalance,t.currentBalance}async redeemCode(t){const e=await this.api.queryServices({cmd:"redeem",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,id:this.account.id,code:t});return e.result==="SUCCESS"?(this.account.eggBalance=e.eggs_given,e.item_ids.forEach(a=>this.account.ownedItemIds.push(a)),{result:e,eggsGiven:e.eggs_given,itemIds:e.item_ids}):e}async claimURLReward(t){const e=await this.api.queryServices({cmd:"urlRewardParams",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,reward:t});return e.result==="SUCCESS"&&(this.account.eggBalance+=e.eggsGiven,e.itemIds.forEach(a=>this.account.ownedItemIds.push(a))),e}async claimSocialReward(t){const e=await this.api.queryServices({cmd:"reward",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,rewardTag:t});return e.result==="SUCCESS"&&(this.account.eggBalance+=e.eggsGiven,e.itemIds.forEach(a=>this.account.ownedItemIds.push(a))),e}async buyItem(t){const e=await this.api.queryServices({cmd:"buy",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,itemId:t,save:!0});return e.result==="SUCCESS"&&(this.account.eggBalance=e.currentBalance,this.account.ownedItemIds.push(e.itemId)),e}processError(t){if(this.#t.error&&this.#t.error.length)this.emit("error",t);else throw t}leave(t=W.mainMenu){this.hasQuit||(t>-1&&(this.game?.socket?.close(t),this.state.left=!0,this.emit("leave",t)),clearInterval(this.updateIntervalId),this.#e=[],this.state.inGame=!1,this.state.chatLines=0,this.state.reloading=!1,this.state.swappingGun=!1,this.state.usingMelee=!1,this.state.stateIdx=0,this.state.serverStateIdx=0,this.state.shotsFired=0,this.state.buffer=[],this.players={},this.me=new U({}),this.game=this.#n,this.ping=0,this.lastPingTime=-1,this.lastDeathTime=-1,this.lastUpdateTick=0,this.pathing={nodeList:null,followingPath:!1,activePath:null,activeNode:null,activeNodeIdx:0})}logout(){this.account=this.#s}quit(t=!1){this.hasQuit||(this.leave(),this.matchmaker&&(this.matchmaker.close(),t||delete this.matchmaker),t||(delete this.account,delete this.api,delete this.game,delete this.me,delete this.pathing,delete this.players,delete this.state,this.#s={},this.#n={},this.#t={},this.#i=[],this.#e=[]),clearInterval(this.afkKickInterval),this.hasQuit=!0)}}var Ut=nt;export{nt as Bot,Ut as default};
|
|
3
|
+
import Z from"./api.js";import s from"./comm/CommIn.js";import f from"./comm/CommOut.js";import W from"./constants/CloseCode.js";import c from"./constants/CommCode.js";import U from"./bot/GamePlayer.js";import $ from"./matchmaker.js";import q from"./socket.js";import{ChiknWinnerDailyLimit as Y,CollectType as x,CoopState as y,findItemById as g,FramesBetweenSyncs as w,GameAction as E,GameMode as p,GameOptionFlag as X,GunList as J,ItemType as V,Movement as b,PlayType as F,ProxiesEnabled as Q,ShellStreak as u,StateBufferSize as S}from"./constants/index.js";import G from"./dispatches/LookAtPosDispatch.js";import O from"./dispatches/MovementDispatch.js";import{NodeList as tt}from"./pathing/mapnode.js";import{coords as et}from"./wasm/wrapper.js";import{fetchMap as st,initKotcZones as at}from"./util.js";import{Challenges as it}from"./constants/challenges.js";import{Maps as _}from"./constants/maps.js";import{Regions as R}from"./constants/regions.js";const M=Object.fromEntries(Object.entries(y).map(([k,t])=>[t,k.toLowerCase()])),A=Object.fromEntries(Object.entries(p).map(([k,t])=>[t,k])),L=Object.fromEntries(Object.entries(X).map(([k,t])=>[k[0].toLowerCase()+k.slice(1),t])),N={CHALLENGES:1,STATS:2,PATHFINDING:3,PING:5,COSMETIC_DATA:6,PLAYER_HEALTH:7,PACKET_HOOK:8,LOG_PACKETS:10,NO_LOGIN:11,DEBUG_BUFFER:12,DEBUG_BEST_TARGET:14,NO_AFK_KICK:16,LOAD_MAP:17,OBSERVE_GAME:18,NO_REGION_CHECK:19,NO_EXIT_ON_ERROR:20},v=(k,t)=>(k%t+t)%t;class nt{static Intents=N;Intents=N;#e=[];#t={};#i=[];#s;#n;constructor(t={}){t.proxy&&!Q&&this.processError("proxies do not work and hence are not supported in the browser"),this.intents=t.intents||[],this.intents.includes(this.Intents.COSMETIC_DATA)&&(g(1001)||this.processError("you cannot use the COSMETIC_DATA intent inside of the singlefile browser bundles")),this.instance=t.instance||"shellshock.io",this.protocol=t.protocol||"wss",this.proxy=t.proxy||"",this.httpProxy=t.httpProxy||"",this.state={name:"yolkbot",weaponIdx:0,inGame:!1,chatLines:0,yaw:0,pitch:0,controlKeys:0,reloading:!1,swappingGun:!1,usingMelee:!1,stateIdx:0,serverStateIdx:0,shotsFired:0,buffer:[],left:!1},this.players={},this.me=new U({}),this.game={raw:{},code:"",socket:null,gameModeId:0,gameMode:A[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.#n=this.game,this.account={id:0,firebase:{idToken:"",refreshToken:"",expiresIn:"3600",localId:""},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,emailVerified:!1,isAged:!1,eggBalance:0,adminRoles:0,rawLoginData:{},isDoubleEggWeeknd:()=>{const e=new Date().getUTCDay(),a=new Date().getUTCHours();return e>=5&&a>=20||e===6||e===0}},this.#s=this.account,this.matchmaker=null,this.api=new Z({instance:this.instance,protocol:this.protocol,proxy:this.proxy,httpProxy:this.httpProxy,maxRetries:t?.apiMaxRetries}),this.ping=0,this.lastPingTime=-1,this.lastDeathTime=-1,this.lastUpdateTick=0,this.pathing={nodeList:null,followingPath:!1,activePath:null,activeNode:null,activeNodeIdx:0},this.hasQuit=!1,this.intents.includes(this.Intents.NO_AFK_KICK)&&(this.afkKickInterval=0)}dispatch(t){return t.validate(this)?(t.check(this)?t.execute(this):this.#e.push(t),!0):!1}async createAccount(t,e){this.account=this.#s,this.account.email=t,this.account.password=e;const a=await this.api.createAccount(t,e);return this.processLoginData(a)}async login(t,e){this.account=this.#s,this.account.email=t,this.account.password=e;const a=await this.api.loginWithCredentials(t,e);return this.processLoginData(a)}async loginWithRefreshToken(t){this.account=this.#s;const e=await this.api.loginWithRefreshToken(t);return this.processLoginData(e)}async loginAnonymously(){this.account=this.#s;const t=await this.api.loginAnonymously();return this.processLoginData(t)}processLoginData(t){return typeof t!="object"?(this.emit("authFail",t),t):t.banRemaining?(this.emit("banned",t.banRemaining),"account_banned"):t.playerOutput?(this.account.firebase=t.firebase||{},t=t.playerOutput,this.account.rawLoginData=t,this.account.adminRoles=t.adminRoles||0,this.account.eggBalance=t.currentBalance,this.account.emailVerified=t.emailVerified,this.account.firebaseId=t.firebaseId,this.account.id=t.id,this.account.isAged=new Date(t.dateCreated).getTime()<17145468e5,this.account.loadout=t.loadout,this.account.ownedItemIds=t.ownedItemIds,this.account.session=t.session,this.account.sessionId=t.sessionId,this.account.vip=t.active_sub==="IsVIP",this.intents.includes(this.Intents.STATS)&&(this.account.stats={lifetime:t.statsLifetime,monthly:t.statsCurrent}),this.intents.includes(this.Intents.CHALLENGES)&&this.#a(t.challenges),this.emit("authSuccess",this.account),this.account):(this.emit("authFail",t),t)}#a(t){this.account.challenges=[];for(const e of t){const a=it.find(i=>i.id===e.challengeId);a&&(delete e.playerId,this.account.challenges.push({raw:{challengeInfo:a,challengeData:e},id:e.challengeId,name:a.loc.title,desc:a.loc.desc,rewardEggs:a.reward,isRerolled:!!e.reset,isClaimed:!!e.claimed,isCompleted:!!e.completed,progressNum:e.progress,goalNum:a.goal}))}}async initMatchmaker(){if(!this.account.sessionId&&!this.intents.includes(this.Intents.NO_LOGIN)){const t=await this.loginAnonymously();if(typeof t!="object")return t}return this.matchmaker||(this.matchmaker=new $({sessionId:this.account.sessionId,proxy:this.proxy,instance:this.instance,protocol:this.protocol,noLogin:this.intents.includes(this.Intents.NO_LOGIN),api:this.api}),this.matchmaker.on("authFail",t=>this.emit("authFail",t)),this.matchmaker.on("error",t=>this.processError(t)),await this.matchmaker.getRegions()),!0}async findPublicGame(t,e){return typeof t!="string"?"no_region_passed":!R.find(i=>i.id===t)&&!this.intents.includes(this.Intents.NO_REGION_CHECK)?"invalid_region_passed":typeof e!="number"?"no_mode_passed":Object.values(p).indexOf(e)===-1?"invalid_mode_passed":await this.initMatchmaker()?await new Promise(i=>{const o=n=>{n.command==="gameFound"&&(this.matchmaker.off("msg",o),i(n))};this.matchmaker.on("msg",o),this.matchmaker.send({command:"findGame",region:t,playType:F.JoinPublic,gameType:e,sessionId:this.sessionId})}):"matchmaker_init_fail"}async createPrivateGame(t,e,a){if(typeof t!="string")return"no_region_passed";if(!R.find(n=>n.id===t)&&!this.intents.includes(this.Intents.NO_REGION_CHECK))return"invalid_region_passed";if(typeof e!="number")return"no_mode_passed";if(Object.values(p).indexOf(e)===-1)return"invalid_mode_passed";if(typeof a!="string")return"no_map_passed";const i=_.findIndex(n=>n.name.toLowerCase()===a.toLowerCase());return i===-1?"invalid_map_passed":await this.initMatchmaker()?await new Promise(n=>{const r=m=>{m.command==="gameFound"&&(this.matchmaker.off("msg",r),n(m))};this.matchmaker.on("msg",r),this.matchmaker.send({command:"findGame",region:t,playType:F.CreatePrivate,gameType:e,sessionId:this.account.sessionId,noobLobby:!1,map:i})}):"matchmaker_init_fail"}async join(t,e){if(this.state.name=t||"yolkbot",typeof e=="string"){if(e.includes("#")&&(e=e.split("#")[1]),!await this.initMatchmaker())return"matchmakerInitFail";const i=await new Promise(o=>{const n=r=>{if(r.command==="gameFound"&&(this.matchmaker.off("msg",n),this.game.raw=r,this.game.code=r.id,o(r.id)),r.error&&r.error==="gameNotFound")return this.processError(`game "${e}" not found, it may have expired.`),this.leave(),"gameNotFound"};this.matchmaker.on("msg",n),this.matchmaker.send({command:"joinGame",id:e,observe:!1,sessionId:this.account.sessionId})});if(i==="matchmakerInitFail")return this.processError("failed to create matchmaker, you may be ratelimited (try a vpn?)");if(i==="gameNotFound")return this.processError("game not found, it may have expired or been deleted");if(!this.game.raw.id)return this.processError("an internal error occured while joining the game, please report this to developers")}if(typeof e=="object"){if(this.account.id===0&&await this.loginAnonymously(),this.game.raw=e,this.game.code=this.game.raw.id,!this.game.raw.id)return this.processError("invalid game object passed to join (missing id)");if(!this.game.raw.subdomain)return this.processError("invalid game object passed to join (missing subdomain)");if(!this.game.raw.uuid)return this.processError("invalid game object passed to join (missing uuid)")}const a=async()=>{try{const i=this.instance.startsWith("localhost:")?this.instance:`${this.game.raw.subdomain}.${this.instance}`;this.game.socket=new q(`${this.protocol}://${i}/game/${this.game.raw.id}`,this.proxy),this.game.socket.onerror=async o=>(this.processError(o),await new Promise(n=>setTimeout(n,100)),await a())}catch{await new Promise(i=>setTimeout(i,100)),await a()}};await a(),this.game.socket.binaryType="arraybuffer",this.game.socket.onopen=()=>this.game.socket.onerror=null,this.game.socket.onmessage=i=>this.processPacket(i.data),this.game.socket.onclose=i=>{this.state.left?this.state.left=!1:(this.emit("close",i.code),this.leave(-1))}}#o(){if(Object.entries(this.me.position).map(e=>Math.floor(e[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 O(0));else{let e;this.pathing.activeNodeIdx<this.pathing.activePath.length-1?(e=this.pathing.activePath[this.pathing.activeNodeIdx+1].flatCenter(),this.dispatch(new G(e))):(e=this.pathing.activePath[this.pathing.activeNodeIdx].flatCenter(),this.dispatch(new G(e)));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.state.controlKeys&b.Forward||this.dispatch(new O(b.Forward))}}update(){if(!this.hasQuit){if(this.pathing.followingPath&&this.intents.includes(this.Intents.PATHFINDING)&&this.#o(),this.#e.length>0)for(let t=0;t<this.#e.length;t++){const e=this.#e[t];e.check(this)&&(e.execute(this),this.#e.splice(t,1))}if(this.state.chatLines=Math.max(0,this.state.chatLines-1/(30*4)),this.me.playing){const t=this.state.stateIdx;if(this.intents.includes(this.Intents.DEBUG_BUFFER)&&(console.log("setting buffer for idx",t),console.log("checking...shotsFired",this.state.shotsFired)),this.me.jumping=!!(this.state.controlKeys&b.Jump),this.state.buffer[t]={controlKeys:this.state.controlKeys,yaw:this.state.yaw,pitch:this.state.pitch,shotsFired:this.state.shotsFired},this.state.shotsFired=0,this.lastUpdateTick>=2){this.emit("tick");const e=new f;e.packInt8(c.syncMe),e.packInt8(this.state.stateIdx),e.packInt8(this.state.serverStateIdx);const a=v(this.state.stateIdx-w+1,S);for(let i=0;i<w;i++){const o=v(a+i,S);this.intents.includes(this.Intents.DEBUG_BUFFER)&&console.log("going with",this.state.stateIdx,a,o,this.state.buffer[o]),e.packInt8(this.state.buffer[o]?.controlKeys||0),e.packInt8(this.state.buffer[o]?.shotsFired||0);const n=this.state.buffer[o]?.yaw||this.state.yaw,r=this.state.buffer[o]?.pitch||this.state.pitch,m=et(n,r);e.packString(m),e.packInt8(100)}e.send(this.game.socket),this.state.buffer=[],this.lastUpdateTick=0}else this.lastUpdateTick++;this.state.stateIdx=v(this.state.stateIdx+1,S)}if(this.intents.includes(this.Intents.PLAYER_HEALTH))for(const t of Object.values(this.players)){if(t.playing&&t.hp>0){const e=.1*(this.game.isPrivate?this.game.options.healthRegen:1);t.streakRewards.includes(u.OverHeal)?t.hp=Math.max(100,t.hp-e):t.hp=Math.min(100,t.hp+e)}t.spawnShield>0&&(t.spawnShield-=6)}}}on(t,e){Object.keys(this.#t).includes(t)?this.#t[t].push(e):this.#t[t]=[e]}once(t,e){const a=(...i)=>{e(...i),this.off(t,a)};this.on(t,a)}onAny(t){this.#i.push(t)}off(t,e){e?this.#t[t]=this.#t[t].filter(a=>a!==e):this.#t[t]=[]}emit(t,...e){if(!this.hasQuit){if(this.#t[t])for(const a of this.#t[t])a(...e);for(const a of this.#i)a(t,...e)}}#c(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=s.unPackString().valueOf(),i=this.players[t];this.emit("chat",i,a,e)}#r(){const t=s.unPackInt8U(),e=this.intents.includes(this.Intents.COSMETIC_DATA),a={id:t,uniqueId:s.unPackString(),name:s.unPackString(),safeName:s.unPackString(),charClass:s.unPackInt8U(),team:s.unPackInt8U(),primaryWeaponItem:e?g(s.unPackInt16U()):s.unPackInt16U(),secondaryWeaponItem:e?g(s.unPackInt16U()):s.unPackInt16U(),shellColor:s.unPackInt8U(),hatItem:e?g(s.unPackInt16U()):s.unPackInt16U(),stampItem:e?g(s.unPackInt16U()):s.unPackInt16U(),stampPosX:s.unPackInt8(),stampPosY:s.unPackInt8(),grenadeItem:e?g(s.unPackInt16U()):s.unPackInt16U(),meleeItem:e?g(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(),bestStreak: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()};this.game.mapIdx=s.unPackInt8U(),this.game.isPrivate=s.unPackInt8U()===1,this.game.gameModeId=s.unPackInt8U();const i=new U(a,this.game.gameMode===p.KOTC?this.game.activeZone:null);this.players[a.id]||(this.players[a.id]=i),this.emit("playerJoin",i),this.me.id===a.id&&(this.me=i,this.emit("botJoin",this.me))}#h(){const t=s.unPackInt8U(),e=s.unPackInt16U(),a=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackFloat(),n=s.unPackInt8U(),r=s.unPackInt8U(),m=s.unPackInt8U(),d=s.unPackInt8U(),I=s.unPackInt8U(),h=this.players[t];h&&(h.playing=!0,h.randomSeed=e,h.weapons[0]&&h.weapons[0].ammo&&(h.weapons[0].ammo.rounds=n),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:i,z:o},h.spawnShield=120,this.emit("playerRespawn",h))}#l(){const t=s.unPackInt8U(),e=s.unPackFloat(),a=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackInt8U(),n=this.players[t];if(!n||n.id===this.me.id){for(let d=0;d<w;d++)s.unPackInt8U(),s.unPackRadU(),s.unPackRad(),s.unPackInt8U();return}for(let d=0;d<w;d++)s.unPackInt8U()&b.Jump?n.jumping=!0:n.jumping=!1,n.view.yaw=s.unPackRadU(),n.view.pitch=s.unPackRad(),s.unPackInt8U();const r=n.position.x!==e||n.position.y!==a||n.position.z!==i||n.climbing!==o,m=r?{...n.position}:null;if(n.position.x!==e&&(n.position.x=e),n.position.z!==i&&(n.position.z=i),(!n.jumping||Math.abs(n.position.y-a)>.5&&n.position.y!==a)&&(n.position.y=a),n.climbing!==o&&(n.climbing=o),r&&(this.emit("playerMove",n,m,n.position),this.game.gameModeId===p.KOTC)){const d=this.game.activeZone;if(!d){n.inKotcZone&&(n.inKotcZone=!1,this.emit("playerLeaveZone",n));return}const I=!!n.inKotcZone;n.updateKotcZone(d),!n.inKotcZone&&I?(n.inKotcZone=!1,this.emit("playerLeaveZone",n)):n.inKotcZone&&!I&&(n.inKotcZone=!0,this.emit("playerEnterZone",n))}}#m(){const t=s.unPackInt8U(),e=this.players[t];e&&(e.playing=!1,e.streakRewards&&(e.streakRewards=[]),this.emit("playerPause",e),e.inKotcZone&&(e.inKotcZone=!1,this.emit("playerLeaveZone",e)))}#u(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];a&&(a.activeGun=e,this.emit("playerSwapWeapon",a,e))}#d(){const t=s.unPackInt8U(),e=s.unPackInt8U();s.unPackInt8U(),s.unPackInt8U(),s.unPackInt8U();const a=this.players[t],i=this.players[e];a&&(a.id===this.me.id&&(this.lastDeathTime=Date.now()),a.playing=!1,a.streak=0,a.hp=100,a.spawnShield=0,a.stats.totalDeaths++,a.inKotcZone=!1,this.emit("playerLeaveZone",a)),i&&(i.streak++,i.stats.totalKills++,i.streak>i.stats.bestStreak&&(i.stats.bestStreak=i.streak)),this.emit("playerDeath",a,i)}#p(){const t=s.unPackInt8U(),e={posX:s.unPackFloat(),posY:s.unPackFloat(),posZ:s.unPackFloat(),dirX:s.unPackFloat(),dirY:s.unPackFloat(),dirZ:s.unPackFloat()},a=this.players[t];if(!a)return;const i=a.weapons[a.activeGun];i&&i.ammo&&(i.ammo.rounds--,this.emit("playerFire",a,i,e))}#g(){const t=s.unPackInt16U(),e=s.unPackInt8U(),a=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackFloat();this.game.collectables[e].push({id:t,x:a,y:i,z:o}),this.emit("spawnItem",e,{x:a,y:i,z:o})}#k(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=s.unPackInt8U(),i=s.unPackInt16U(),o=this.players[t];if(this.game.collectables[e]=this.game.collectables[e].filter(n=>n.id!==i),e===x.Ammo){const n=o.weapons[a];n&&n.ammo&&(n.ammo.store=Math.min(n.ammo.storeMax,n.ammo.store+n.ammo.pickup),this.emit("collectAmmo",o,n))}e===x.Grenade&&(o.grenades++,o.grenades>3&&(o.grenades=3),this.emit("collectGrenade",o))}#f(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];if(!a)return;const i=a.hp;a.hp=e,this.emit("playerDamage",a,i,a.hp)}#I(){const t=s.unPackInt8U();s.unPackFloat(),s.unPackFloat();const e=this.me.hp;this.me.hp=t,this.emit("playerDamage",this.me,e,this.me.hp)}#P(){const t=s.unPackInt8U(),e=this.players[t];s.unPackInt8U();const a=s.unPackInt8U(),i=s.unPackFloat(),o=s.unPackFloat(),n=s.unPackFloat();if(this.me.climbing=!!s.unPackInt8U(),s.unPackInt8U(),s.unPackInt8U(),!e)return;this.state.serverStateIdx=a;const r=e.position.x,m=e.position.y,d=e.position.z;e.position.x=i,e.position.y=o,e.position.z=n,(r!==i||m!==o||d!==n)&&this.emit("playerMove",e,{x:r,y:m,z:d},{x:i,y:o,z:n})}#y(){const t=new f;t.packInt8(c.eventModifier),t.send(this.game.socket)}#w(){const t=s.unPackInt8U(),e={...this.players[t]};delete this.players[t.toString()],this.emit("playerLeave",e)}#b(){if(this.game.gameModeId===p.Spatula){const t={...this.game};this.game.teamScore[1]=s.unPackInt16U(),this.game.teamScore[2]=s.unPackInt16U();const e={x:s.unPackFloat(),y:s.unPackFloat(),z:s.unPackFloat()},a=s.unPackInt8U(),i=s.unPackInt8U();this.game.spatula={coords:e,controlledBy:a,controlledByTeam:i},this.emit("gameStateChange",t,this.game)}else if(this.game.gameModeId===p.KOTC){const t={...this.game};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.game.activeZone&&Object.values(this.players).forEach(e=>e.updateKotcZone(this.game.activeZone)),this.game.numCapturing<=0&&Object.values(this.players).forEach(e=>{e.inKotcZone=!1,this.emit("playerLeaveZone",e)}),this.emit("gameStateChange",t,this.game)}else this.game.gameModeId===p.Team&&(this.game.teamScore[1]=s.unPackInt16U(),this.game.teamScore[2]=s.unPackInt16U());this.game.gameModeId!==p.Spatula&&delete this.game.spatula,this.game.gameModeId!==p.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===p.FFA&&delete this.game.teamScore}#U(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];switch(e){case u.HardBoiled:t===this.me.id&&(this.me.shieldHp=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,e)}#S(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];[u.EggBreaker,u.OverHeal,u.DoubleEggs,u.MiniEgg].includes(e)&&a.streakRewards.includes(e)&&(a.streakRewards=a.streakRewards.filter(o=>o!==e)),this.emit("playerEndStreak",a,e)}#v(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=s.unPackFloat(),i=s.unPackFloat();this.me.shieldHp=t,this.me.hp=e,this.me.shieldHp<=0?(this.me.streakRewards=this.me.streakRewards.filter(o=>o!==u.HardBoiled),this.emit("selfShieldLost",this.me.hp,{dx:a,dz:i})):this.emit("selfShieldHit",this.me.shieldHp,this.me.hp,{dx:a,dz:i})}#C(){const t={...this.game.options};let e=s.unPackInt8U(),a=s.unPackInt8U(),i=s.unPackInt8U();(e<1||e>4)&&(e=4),(a<0||a>8)&&(a=4),i>16&&(i=4),this.game.options.gravity=e/4,this.game.options.damage=a/4,this.game.options.healthRegen=i/4;const o=s.unPackInt8U();Object.keys(L).forEach(n=>{const r=o&L[n]?1:0;this.game.options[n]=r}),this.game.options.weaponsDisabled=Array.from({length:7},()=>s.unPackInt8U()===1),this.game.options.mustUseSecondary=this.game.options.weaponsDisabled.every(n=>n),this.emit("gameOptionsChange",t,this.game.options)}#T(){const t=s.unPackInt8U();t===E.Pause&&(this.emit("gameForcePause"),setTimeout(()=>this.me.playing=!1,3e3)),t===E.Reset&&(Object.values(this.players).forEach(e=>e.streak=0),this.game.gameModeId!==p.FFA&&(this.game.teamScore=[0,0,0]),this.game.gameModeId===p.Spatula&&(this.game.spatula.controlledBy=0,this.game.spatula.controlledByTeam=0,this.game.spatula.coords={x:0,y:0,z:0}),this.game.gameModeId===p.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"))}#x(){if(!this.intents.includes(this.Intents.PING))return;const t=this.ping;this.ping=Date.now()-this.lastPingTime,this.emit("pingUpdate",t,this.ping),setTimeout(()=>{const e=new f;e.packInt8(c.ping),e.send(this.game.socket),this.lastPingTime=Date.now()},1e3)}#E(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];if(!a)return;const i=a.team;a.team=e,a.streak=0,this.emit("playerSwitchTeam",a,i,e)}#F(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=s.unPackInt16U(),i=s.unPackInt16U(),o=s.unPackInt8U(),n=s.unPackInt16U(),r=s.unPackInt16U(),m=s.unPackInt16U(),d=s.unPackInt16U(),I=s.unPackInt8(),h=s.unPackInt8(),P=this.intents.includes(this.Intents.COSMETIC_DATA),B=P?g(a):a,D=P?g(i):i,K=P?g(n):n,H=P?g(r):r,j=P?g(m):m,z=P?g(d):d,l=this.players[t];if(l){const C={...l.character},T=l.selectedGun;l.character.eggColor=o,l.character.primaryGun=B,l.character.secondaryGun=D,l.character.stamp=H,l.character.hat=K,l.character.grenade=j,l.character.melee=z,l.character.stampPos.x=I,l.character.stampPos.y=h,l.selectedGun=e,l.weapons[0]=new J[e],T!==l.selectedGun&&this.emit("playerChangeGun",l,T,l.selectedGun),C!==l.character&&this.emit("playerChangeCharacter",l,C,l.character)}}#G(){const t=s.unPackInt32U(),e=this.account.eggBalance;this.account.eggBalance=t,this.emit("balanceUpdate",e,t)}#O(){this.me.playing=!1,this.emit("respawnDenied")}#_(){const t=s.unPackInt8U(),e=this.players[t];e&&this.emit("playerMelee",e)}#R(){const t=s.unPackInt8U(),e=this.players[t];if(!e)return;const a=e.weapons[e.activeGun];if(a.ammo){const i=Math.min(Math.min(a.ammo.capacity,a.ammo.reload)-a.ammo.rounds,a.ammo.store);a.ammo.rounds+=i,a.ammo.store-=i}this.emit("playerReload",e,a)}updateGameOptions(){const t=new f;t.packInt8(c.gameOptions),t.packInt8(this.game.options.gravity*4),t.packInt8(this.game.options.damage*4),t.packInt8(this.game.options.healthRegen*4);const e=(this.game.options.locked?1:0)|(this.game.options.noTeamChange?2:0)|(this.game.options.noTeamShuffle?4:0);t.packInt8(e),this.game.options.weaponsDisabled.forEach(a=>{t.packInt8(a?1:0)}),t.send(this.game.socket)}#M(){this.game.isPrivate=!0,this.updateGameOptions()}#A(){const t=s.unPackInt8U();let e=s.unPackInt16U();const a=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackFloat(),n=s.unPackInt8U(),r=s.unPackFloat();this.intents.includes(this.Intents.COSMETIC_DATA)&&(e=g(e)),t===V.Grenade?this.emit("grenadeExplode",e,{x:a,y:i,z:o},n,r):this.emit("rocketHit",{x:a,y:i,z:o},n,r)}#L(){const t=s.unPackInt8U(),e=s.unPackFloat(),a=s.unPackFloat(),i=s.unPackFloat(),o=s.unPackFloat(),n=s.unPackFloat(),r=s.unPackFloat(),m=this.players[t];m&&(m.grenades--,this.emit("playerThrowGrenade",m,{x:e,y:a,z:i},{x:o,y:n,z:r}))}#N(){const t=s.unPackInt8U(),e=s.unPackInt8U(),a=this.players[t];if(!a)return;if(!this.intents.includes(this.Intents.CHALLENGES))return this.emit("challengeComplete",a,e);const i=this.account.challenges.find(o=>o.id===e);this.emit("challengeComplete",a,i),a.id===this.me.id&&this.refreshChallenges()}#B(){const t=new f;t.packInt8(this.intents.includes(this.Intents.OBSERVE_GAME)?c.observeGame:c.joinGame),t.packString(this.state.name),t.packString(this.game.raw.uuid),t.packInt8(0),t.packInt8(this.state.weaponIdx||this.account?.loadout?.classIdx||0),t.packInt32(this.account.session),t.packString(this.account.firebaseId),t.packString(this.account.sessionId),t.send(this.game.socket)}async#D(){if(this.me.id=s.unPackInt8U(),this.me.team=s.unPackInt8U(),this.game.gameModeId=s.unPackInt8U(),this.game.gameMode=A[this.game.gameModeId],this.game.mapIdx=s.unPackInt8U(),this.game.map=_[this.game.mapIdx],this.game.playerLimit=s.unPackInt8U(),this.game.isGameOwner=s.unPackInt8U()===1,this.game.isPrivate=s.unPackInt8U()===1||this.game.isGameOwner,s.unPackInt8U(),this.intents.includes(this.Intents.LOAD_MAP)||this.intents.includes(this.Intents.PATHFINDING)){if(this.game.map.raw=await st(this.game.map.filename,this.game.map.hash),this.emit("mapLoad",this.game.map.raw),this.game.gameModeId===p.KOTC){const e=this.game.map.raw.data["DYNAMIC.capture-zone.none"];e?(this.game.map.zones=at(e),this.game.activeZone||(this.game.activeZone=this.game.map.zones[this.game.zoneNumber-1])):delete this.game.map.zones}this.intents.includes(this.Intents.PATHFINDING)&&(this.pathing.nodeList=new tt(this.game.map.raw))}this.state.inGame=!0,this.lastDeathTime=Date.now();const t=new f;if(t.packInt8(c.clientReady),t.send(this.game.socket),this.updateIntervalId=setInterval(()=>this.update(),100/3),this.intents.includes(this.Intents.PING)){this.lastPingTime=Date.now();const e=new f;e.packInt8(c.ping),e.send(this.game.socket)}this.afkKickInterval=setInterval(()=>{if(this.state.inGame&&!this.me.playing&&Date.now()-this.lastDeathTime>=15e3){const e=new f;e.packInt8(c.keepAlive),e.send(this.game.socket)}},15e3),this.emit("gameReady")}#K(){const t=s.unPackInt8U(),e=s.unPackString(128),a=s.unPackString(32);if(!this.players[t])return;const i=this.players[t];i.admin={ip:a,dbId:e},this.emit("playerInfo",i,a,e)}processPacket(t){s.init(t),this.intents.includes(this.Intents.PACKET_HOOK)&&this.emit("packet",t);let e=0,a=0,i=!1;for(;s.isMoreDataAvailable()&&!i;){const o=s.unPackInt8U();switch(o){case c.syncThem:this.#l();break;case c.fire:this.#p();break;case c.hitThem:this.#f();break;case c.syncMe:this.#P();break;case c.hitMe:this.#I();break;case c.swapWeapon:this.#u();break;case c.collectItem:this.#k();break;case c.respawn:this.#h();break;case c.die:this.#d();break;case c.pause:this.#m();break;case c.chat:this.#c();break;case c.addPlayer:this.#r();break;case c.removePlayer:this.#w();break;case c.eventModifier:this.#y();break;case c.metaGameState:this.#b();break;case c.beginShellStreak:this.#U();break;case c.endShellStreak:this.#S();break;case c.hitMeHardBoiled:this.#v();break;case c.gameOptions:this.#C();break;case c.ping:this.#x();break;case c.switchTeam:this.#E();break;case c.changeCharacter:this.#F();break;case c.reload:this.#R();break;case c.explode:this.#A();break;case c.throwGrenade:this.#L();break;case c.spawnItem:this.#g();break;case c.melee:this.#_();break;case c.updateBalance:this.#G();break;case c.challengeCompleted:this.#N();break;case c.socketReady:this.#B();break;case c.gameJoined:this.#D();break;case c.gameAction:this.#T();break;case c.requestGameOptions:this.#M();break;case c.respawnDenied:this.#O();break;case c.playerInfo:this.#K();break;case c.expireUpgrade:case c.clientReady:break;case c.musicInfo:s.unPackLongString();break;default:console.error(`processPacket: I got but couldn't identify a: ${Object.keys(c).find(n=>c[n]===o)} ${o}`),e&&console.error(`processPacket: It may be a result of the ${e} command (${a}).`),i=!0;break}e=Object.keys(c).find(n=>c[n]===o),a=o,this.intents.includes(this.Intents.LOG_PACKETS)&&console.log(`[LOG_PACKETS] Packet ${e}: ${a}`)}}async checkChiknWinner(){const t=await this.api.queryServices({cmd:"chicknWinnerReady",id:this.account.id,sessionId:this.account.sessionId});return typeof t=="string"?t:(this.account.cw.limit=t.limit,this.account.cw.atLimit=t.limit>=4,this.account.cw.secondsUntilPlay=(this.account.cw.atLimit?t.period:t.span)||0,this.account.cw.canPlayAgain=Date.now()+this.account.cw.secondsUntilPlay*1e3,this.account.cw)}async playChiknWinner(t=!0){if(this.account.cw.atLimit||this.account.cw.limit>Y)return"hit_daily_limit";if(this.account.cw.canPlayAgain>Date.now()&&t)return"on_cooldown";const e=await this.api.queryServices({cmd:"incentivizedVideoReward",firebaseId:this.account.firebaseId,id:this.account.id,sessionId:this.account.sessionId,token:null});return typeof e=="string"?e:e.error?e.error==="RATELIMITED"||e.error==="RATELMITED"?(await this.checkChiknWinner(),"on_cooldown"):e.error==="SESSION_EXPIRED"?"session_expired":(console.error("Unknown Chikn Winner response, report this on Github:",e),"unknown_error"):e.reward?(this.account.eggBalance+=e.reward.eggsGiven,e.reward.itemIds.forEach(a=>this.account.ownedItemIds.push(a)),await this.checkChiknWinner(),e.reward):(console.error("Unknown Chikn Winner response, report this on Github:",e),"unknown_error")}async resetChiknWinner(){if(this.account.eggBalance<200)return"not_enough_eggs";if(!this.account.cw.atLimit)return"not_at_limit";const t=await this.api.queryServices({cmd:"chwReset",sessionId:this.account.sessionId});return typeof t=="string"?t:t.result!=="SUCCESS"?(console.error("Unknown Chikn Winner reset response, report this on Github:",t),"unknown_error"):(this.account.eggBalance-=200,await this.checkChiknWinner(),this.account.cw)}canSee(t){return this.intents.includes(this.Intents.PATHFINDING)?this.pathing.nodeList.hasLineOfSight(this.me.position,t.position):this.processError("You must have the PATHFINDING intent to use this method.")}getBestTarget(t=()=>!0){const a=Object.values(this.players).filter(o=>o?.playing).filter(o=>o.hp>0).filter(o=>o.id!==this.me.id).filter(o=>this.me.team===0||o.team!==this.me.team).filter(o=>!!t(o)).map(o=>({player:o,distance:Math.sqrt(Math.pow(o.position.x-this.me.position.x,2)+Math.pow(o.position.y-this.me.position.y,2)+Math.pow(o.position.z-this.me.position.z,2))})).sort((o,n)=>o.distance-n.distance);if(!a.length)return this.intents.includes(this.Intents.DEBUG_BEST_TARGET)&&console.log("no targets found"),null;const i=a.find(o=>this.canSee(o.player));return this.intents.includes(this.Intents.DEBUG_BEST_TARGET)&&(console.log("detected ",a.length,"targets"),console.log("closest target: ",a[0].player.name),console.log("all targets (ordered): ",a.map(o=>o.player.name)),console.log("found LoS player?",!!i),i&&console.log("closest LoS player: ",i.player.name)),i?{player:i.player,inLoS:!0}:{player:a[0].player,inLoS:!1}}async refreshChallenges(){const t=await this.api.queryServices({cmd:"challengeGetDaily",sessionId:this.account.sessionId,playerId:this.account.id});return this.#a(t),this.account.challenges}async rerollChallenge(t){const e=await this.api.queryServices({cmd:"challengeRerollSlot",sessionId:this.account.sessionId,slotId:t});return this.#a(e),this.account.challenges}async claimChallenge(t){const e=await this.api.queryServices({cmd:"challengeClaimReward",sessionId:this.account.sessionId,slotId:t});return this.#a(e.challenges),e.reward>0&&(this.account.eggBalance+=e.reward),{eggReward:e.reward,updatedChallenges:this.account.challenges}}async refreshBalance(){const t=await this.api.queryServices({cmd:"checkBalance",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId});return this.account.eggBalance=t.currentBalance,t.currentBalance}async redeemCode(t){const e=await this.api.queryServices({cmd:"redeem",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,id:this.account.id,code:t});return e.result==="SUCCESS"?(this.account.eggBalance=e.eggs_given,e.item_ids.forEach(a=>this.account.ownedItemIds.push(a)),{result:e,eggsGiven:e.eggs_given,itemIds:e.item_ids}):e}async claimURLReward(t){const e=await this.api.queryServices({cmd:"urlRewardParams",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,reward:t});return e.result==="SUCCESS"&&(this.account.eggBalance+=e.eggsGiven,e.itemIds.forEach(a=>this.account.ownedItemIds.push(a))),e}async claimSocialReward(t){const e=await this.api.queryServices({cmd:"reward",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,rewardTag:t});return e.result==="SUCCESS"&&(this.account.eggBalance+=e.eggsGiven,e.itemIds.forEach(a=>this.account.ownedItemIds.push(a))),e}async buyItem(t){const e=await this.api.queryServices({cmd:"buy",firebaseId:this.account.firebaseId,sessionId:this.account.sessionId,itemId:t,save:!0});return e.result==="SUCCESS"&&(this.account.eggBalance=e.currentBalance,this.account.ownedItemIds.push(e.itemId)),e}processError(t){this.#t.error&&this.#t.error.length?this.emit("error",t):(console.error(t),this.intents.includes(this.Intents.NO_EXIT_ON_ERROR)||process.exit(1))}leave(t=W.mainMenu){this.hasQuit||(t>-1&&(this.game?.socket?.close(t),this.state.left=!0,this.emit("leave",t)),clearInterval(this.updateIntervalId),this.#e=[],this.state.inGame=!1,this.state.chatLines=0,this.state.reloading=!1,this.state.swappingGun=!1,this.state.usingMelee=!1,this.state.stateIdx=0,this.state.serverStateIdx=0,this.state.shotsFired=0,this.state.buffer=[],this.players={},this.me=new U({}),this.game=this.#n,this.ping=0,this.lastPingTime=-1,this.lastDeathTime=-1,this.lastUpdateTick=0,this.pathing={nodeList:null,followingPath:!1,activePath:null,activeNode:null,activeNodeIdx:0})}logout(){this.account=this.#s}quit(t=!1){this.hasQuit||(this.leave(),this.matchmaker&&(this.matchmaker.close(),t||delete this.matchmaker),t||(delete this.account,delete this.api,delete this.game,delete this.me,delete this.pathing,delete this.players,delete this.state,this.#s={},this.#n={},this.#t={},this.#i=[],this.#e=[]),clearInterval(this.afkKickInterval),this.hasQuit=!0)}}var Ut=nt;export{nt as Bot,Ut as default};
|
package/dist/matchmaker.js
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
/* eslint-disable */
|
|
2
2
|
|
|
3
|
-
import r from"./api.js";import{ProxiesEnabled as h}from"./constants/index.js";import{validate as c}from"./wasm/wrapper.js";import f from"./socket.js";class a{connected=!1;onceConnected=[];regionList=[];proxy=null;sessionId="";onListeners=new Map;onceListeners=new Map;#t=!1;constructor(s={}){s.instance||(s.instance="shellshock.io"),s.protocol||(s.protocol="wss"),s.api?this.api=s.api:this.api=new r({instance:s.instance,protocol:s.protocol,proxy:s.proxy}),s.sessionId||s.noLogin?this.sessionId=s.sessionId:this.#
|
|
3
|
+
import r from"./api.js";import{ProxiesEnabled as h}from"./constants/index.js";import{validate as c}from"./wasm/wrapper.js";import f from"./socket.js";class a{connected=!1;onceConnected=[];regionList=[];proxy=null;sessionId="";onListeners=new Map;onceListeners=new Map;#e=!1;#t=!1;constructor(s={}){this.#e=s.noExitOnError||!1,s.instance||(s.instance="shellshock.io"),s.protocol||(s.protocol="wss"),s.api?this.api=s.api:this.api=new r({instance:s.instance,protocol:s.protocol,proxy:s.proxy}),s.sessionId||s.noLogin?this.sessionId=s.sessionId:this.#n(),s.proxy&&!h?this.#i("proxies do not work and hence are not supported in the browser"):s.proxy&&(this.proxy=s.proxy),this.#o(s.instance,s.protocol,s.noLogin)}async#o(s,i,e){const t=async()=>{try{this.ws=new f(`${i}://${s}/matchmaker/`,this.proxy),this.ws.onerror=async o=>(this.#i(o),await new Promise(n=>setTimeout(n,100)),await t())}catch{await new Promise(o=>setTimeout(o,100)),await t()}};await t(),this.ws.onopen=()=>{this.connected=!0,this.ws.onerror=null,(this.sessionId||e)&&this.onceConnected.forEach(o=>o())},this.ws.onmessage=o=>{const n=JSON.parse(o.data);n.command==="validateUUID"&&this.ws.send(JSON.stringify({command:"validateUUID",hash:c(n.uuid)})),this.#s("msg",n)},this.ws.onclose=()=>{this.connected=!1,this.#t||this.#o(s)}}async#n(){const s=await this.api.loginAnonymously();(!s||typeof s=="string")&&this.#s("authFail",s),this.sessionId=s.sessionId,this.connected&&this.onceConnected.forEach(i=>i())}send(s){this.ws.send(JSON.stringify(s))}async waitForConnect(){return new Promise(s=>{this.connected?s():this.onceConnected.push(s)})}async getRegions(){await this.waitForConnect();const s=this;return new Promise(i=>{const e=t=>{t.command==="regionList"&&(this.regionList=t.regionList,this.off("msg",e),i(t.regionList))};this.on("msg",e),this.ws.onerror=t=>s.#i("failed to get regions",t),this.ws.send(JSON.stringify({command:"regionList"}))})}close(){this.#t=!0,this.connected=!1,this.ws.close()}on(s,i){this.onListeners.has(s)||this.onListeners.set(s,[]),this.onListeners.get(s).push(i)}once(s,i){this.onceListeners.has(s)||this.onceListeners.set(s,[]),this.onceListeners.get(s).push(i)}off(s,i){this.onListeners.has(s)&&this.onListeners.set(s,this.onListeners.get(s).filter(e=>e!==i)),this.onceListeners.has(s)&&this.onceListeners.set(s,this.onceListeners.get(s).filter(e=>e!==i))}#s(s,...i){this.onListeners.has(s)&&this.onListeners.get(s).forEach(e=>e(...i)),this.onceListeners.has(s)&&(this.onceListeners.get(s).forEach(e=>e(...i)),this.onceListeners.delete(s))}#i(s){this.onListeners.has("error")?this.#s("error",s):(console.error(s),this.#e||process.exit(1))}}var y=a;export{a as Matchmaker,y as default};
|
package/dist/types/bot.d.ts
CHANGED