mirror of
https://github.com/exogen/t2-mapper.git
synced 2026-03-15 02:10:55 +00:00
1 line
No EOL
14 KiB
JavaScript
1 line
No EOL
14 KiB
JavaScript
(globalThis.TURBOPACK||(globalThis.TURBOPACK=[])).push(["object"==typeof document?document.currentScript:void 0,0,t=>{"use strict";t.i(91891);var e=t.i(11251),s=t.i(88787);t.i(70847);var a=t.i(47566),i=t.i(25311),o=t.i(89119),r=t.i(10244);class n extends r.StreamEngine{parser;initialBlock;moveTicks=0;absoluteYaw=0;absolutePitch=0;lastAbsYaw=0;lastAbsPitch=0;exhausted=!1;_teamScoresGen=0;_rosterGen=0;_weaponsHudGen=0;_inventoryHudGen=0;_cachedSnapshot=null;_cachedSnapshotTick=-1;_snap=null;constructor(t){super(),this.parser=t,this.registry=t.getRegistry(),this.ghostTracker=t.getGhostTracker();const e=t.initialBlock;this.initialBlock={dataBlocks:e.dataBlocks,initialGhosts:e.initialGhosts,controlObjectGhostIndex:e.controlObjectGhostIndex,controlObjectData:e.controlObjectData,targetEntries:e.targetEntries,sensorGroupColors:e.sensorGroupColors,taggedStrings:e.taggedStrings,initialEvents:e.initialEvents,demoValues:e.demoValues,firstPerson:e.firstPerson},this.reset()}getDataBlockData(t){let e=this.initialBlock.dataBlocks.get(t);if(e?.data)return e.data;let s=this.parser.getPacketParser();return s.dataBlockDataMap?.get(t)}_shapeConstructorCache=null;getShapeConstructorSequences(t){if(!this._shapeConstructorCache)for(let[,t]of(this._shapeConstructorCache=new Map,this.initialBlock.dataBlocks)){if("TSShapeConstructor"!==t.className||!t.data)continue;let e=t.data.shape,s=t.data.sequences;e&&s&&this._shapeConstructorCache.set(e.toLowerCase(),s)}return this._shapeConstructorCache.get(t.toLowerCase())}getTimeSec(){return this.moveTicks*(i.TICK_DURATION_MS/1e3)}getCameraYawPitch(t){let e="player"===this.lastControlType,s=e?this.absoluteYaw:this.lastAbsYaw,a=e?this.absolutePitch:this.lastAbsPitch;return e&&(this.lastAbsYaw=s,this.lastAbsPitch=a),{yaw:s,pitch:a}}getControlPlayerHeadPitch(t){return(0,o.clamp)(this.absolutePitch/o.MAX_PITCH,-1,1)}onTeamScoresChanged(){this._teamScoresGen++}onRosterChanged(){this._rosterGen++}onWeaponsHudChanged(){this._weaponsHudGen++}onInventoryHudChanged(){this._inventoryHudGen++}reset(){for(let[t,e]of(this.parser.reset(),this.ghostTracker=this.parser.getGhostTracker(),this._cachedSnapshot=null,this._cachedSnapshotTick=-1,this._snap=null,this.resetSharedState(),this.initialBlock.taggedStrings))this.netStrings.set(t,e);for(let t of this.initialBlock.targetEntries)t.name&&this.targetNames.set(t.targetId,(0,o.stripTaggedStringMarkup)(t.name)),this.targetTeams.set(t.targetId,t.sensorGroup),this.targetRenderFlags.set(t.targetId,t.targetData);for(let t of this.initialBlock.sensorGroupColors){let e=this.sensorGroupColors.get(t.group);e||(e=new Map,this.sensorGroupColors.set(t.group,e)),e.set(t.targetGroup,{r:t.r,g:t.g,b:t.b})}if(this.moveTicks=0,this.absoluteYaw=0,this.absolutePitch=0,this.lastAbsYaw=0,this.lastAbsPitch=0,this.firstPerson=this.initialBlock.firstPerson,this.lastControlType=(0,o.detectControlObjectType)(this.initialBlock.controlObjectData)??"player",this.isPiloting="player"===this.lastControlType&&!!(this.initialBlock.controlObjectData?.pilot||this.initialBlock.controlObjectData?.controlObjectGhost!=null),this.lastPilotGhostIndex=this.isPiloting&&"number"==typeof this.initialBlock.controlObjectData?.controlObjectGhost?this.initialBlock.controlObjectData.controlObjectGhost:void 0,this.isPiloting){let t=this.initialBlock.controlObjectData?.controlObjectData,e=t?.angPosition;if(e&&"number"==typeof e.w){this.lastVehicleHeading=(0,o.torqueQuatHeading)(e),this.lastVehiclePitch=(0,o.torqueQuatPitch)(e);let t=(0,o.torqueQuatToThreeJS)(e);if(t){let[e,s,a,i]=t;this.lastVehicleOrbitDir=[-(1-2*(s*s+a*a)),-(2*(e*s+a*i)),-(2*(e*a-s*i))]}}}if(this.lastCameraMode="camera"===this.lastControlType&&"number"==typeof this.initialBlock.controlObjectData?.cameraMode?this.initialBlock.controlObjectData.cameraMode:void 0,this.lastOrbitGhostIndex="camera"===this.lastControlType&&"number"==typeof this.initialBlock.controlObjectData?.orbitObjectGhostIndex?this.initialBlock.controlObjectData.orbitObjectGhostIndex:void 0,"camera"===this.lastControlType){let t=this.initialBlock.controlObjectData?.minOrbitDist,e=this.initialBlock.controlObjectData?.maxOrbitDist,s=this.initialBlock.controlObjectData?.curOrbitDist;"number"==typeof t&&"number"==typeof e&&Number.isFinite(t)&&Number.isFinite(e)?this.lastOrbitDistance=Math.max(0,e-t):"number"==typeof s&&Number.isFinite(s)?this.lastOrbitDistance=Math.max(0,s):this.lastOrbitDistance=void 0}else this.lastOrbitDistance=void 0;let t=this.getAbsoluteRotation(this.initialBlock.controlObjectData);for(let e of(t&&(this.absoluteYaw=t.yaw,this.absolutePitch=t.pitch,this.lastAbsYaw=t.yaw,this.lastAbsPitch=t.pitch),this.exhausted=!1,this.latestFov=100,this.latestControl={ghostIndex:this.initialBlock.controlObjectGhostIndex,data:this.initialBlock.controlObjectData,position:(0,o.isValidPosition)(this.initialBlock.controlObjectData?.position)?this.initialBlock.controlObjectData?.position:void 0},this.controlPlayerGhostId="player"===this.lastControlType&&this.initialBlock.controlObjectGhostIndex>=0?(0,i.toEntityId)("Player",this.initialBlock.controlObjectGhostIndex):void 0,this.initialBlock.initialGhosts)){if("create"!==e.type||null==e.classId)continue;let t=this.registry.getGhostParser(e.classId)?.name;if(!t)throw Error(`No ghost parser for classId ${e.classId} (ghost index ${e.index})`);let s=(0,i.toEntityId)(t,e.index),o={id:s,ghostIndex:e.index,className:t,spawnTick:0,type:(0,i.toEntityType)(t),rotation:[0,0,0,1]};if(this.applyGhostData(o,e.parsedData),e.parsedData){let s=(0,a.ghostToSceneObject)(t,e.index,e.parsedData);s&&(o.sceneData=s)}this.entities.set(s,o),this.entityIdByGhostIndex.set(e.index,s)}if(0===this.playerSensorGroup&&"player"===this.lastControlType&&this.latestControl.ghostIndex>=0){let t=this.entityIdByGhostIndex.get(this.latestControl.ghostIndex),e=t?this.entities.get(t):void 0;e?.sensorGroup!=null&&e.sensorGroup>0&&(this.playerSensorGroup=e.sensorGroup)}for(let t of this.initialBlock.initialEvents){let e=this.registry.getEventParser(t.classId)?.name;if("SetSensorGroupEvent"===e&&t.parsedData){let e=t.parsedData.sensorGroup;null!=e&&(this.playerSensorGroup=e)}else if("RemoteCommandEvent"===e&&t.parsedData){let e=this.resolveNetString(t.parsedData.funcName),s=t.parsedData.args;"ServerMessage"===e&&this.handleServerMessage(s),this.handleHudRemoteCommand(e,s)}}let e=function(t){let e={weaponsHud:null,backpackHud:null,inventoryHud:null,teamScores:[],playerRoster:new Map,chatMessages:[],gravity:-20};if(!t.length)return e;let s=0,a=()=>{let e=t[s++];return"<BLANK>"===e?"":e??""};if(a(),s>=t.length)return e;let i=parseInt(a(),10)||0,r=new Map;for(let t=0;t<i;t++){let t=a().split(" "),s=t[0]??"",i=parseInt(t[2],10),o=parseInt(t[4],10);isNaN(i)||isNaN(o)||e.playerRoster.set(i,{name:s,teamId:o}),!isNaN(o)&&o>0&&r.set(o,(r.get(o)??0)+1)}if(s>=t.length||(a(),s>=t.length))return e;{let t=a().split(" "),s=t[0]??"",i="1"===t[1]||"true"===t[1],r=t[2]??"",n="1"===t[4]||"true"===t[4];i&&s&&(e.backpackHud={packIndex:(0,o.backpackBitmapToIndex)(s),active:n,text:r})}if(s>=t.length)return e;let n=a().split(" "),l=parseInt(n[4],10)||0,c=parseInt(n[5],10)||0,h=parseInt(n[6],10);for(let t=0;t<l;t++)a();let p=new Map;for(let t=0;t<c;t++){let t=a().split(" "),e=parseInt(t[0],10),s=parseInt(t[1],10);isNaN(e)||p.set(e,isNaN(s)?-1:s)}if(e.weaponsHud={slots:p,activeIndex:isNaN(h)?-1:h},s>=t.length)return e;let d=a().split(" "),u=parseInt(d[4],10)||0,m=parseInt(d[5],10)||0,k=parseInt(d[6],10);for(let t=0;t<u;t++)a();{let t=new Map;for(let e=0;e<m;e++){let e=a().split(" "),s=parseInt(e[0],10),i=parseInt(e[1],10);isNaN(s)||isNaN(i)||!(i>0)||t.set(s,i)}t.size>0&&(e.inventoryHud={slots:t,activeSlot:isNaN(k)?-1:k})}if(s>=t.length)return e;let b=a().split(" "),g=b[1]??"",y=parseInt(b[2],10)||0,f=[];for(let t=0;t<y;t++)f.push(a());if("CTFGame"===g&&y>=8)for(let t=0;t<2;t++){let s=4*t,a=t+1;e.teamScores.push({teamId:a,name:f[s]??"",score:parseInt(f[s+1],10)||0,playerCount:r.get(a)??0})}else if("TR2Game"===g&&y>=4)for(let t=0;t<2;t++){let s=2*t,a=t+1;e.teamScores.push({teamId:a,name:f[s+1]??"",score:parseInt(f[s],10)||0,playerCount:r.get(a)??0})}if(s>=t.length)return e;a();for(let i=0;i<10&&!(s>=t.length);i++){let t=a();t&&e.chatMessages.push(t)}if(s<t.length){let t=parseFloat(a());Number.isFinite(t)&&(e.gravity=t)}return e}(this.initialBlock.demoValues);for(let t of(e.weaponsHud&&(this.weaponsHud.slots=e.weaponsHud.slots,this.weaponsHud.activeIndex=e.weaponsHud.activeIndex),e.backpackHud&&(this.backpackHud.packIndex=e.backpackHud.packIndex,this.backpackHud.active=e.backpackHud.active,this.backpackHud.text=e.backpackHud.text),e.inventoryHud&&(this.inventoryHud.slots=e.inventoryHud.slots,this.inventoryHud.activeSlot=e.inventoryHud.activeSlot),this.teamScores=e.teamScores,this.playerRoster=new Map(e.playerRoster),e.chatMessages)){let e=(0,o.parseColorSegments)(t);if(!e.length)continue;let s=e.map(t=>t.text).join("");if(!s.trim())continue;let a=e[0].colorCode;if(e.some(t=>3===t.colorCode||4===t.colorCode)&&s.includes(": ")){let t=s.indexOf(": ");this.pushChatMessage({timeSec:0,sender:s.slice(0,t),text:s.slice(t+2),kind:"chat",colorCode:a,segments:e})}else this.pushChatMessage({timeSec:0,sender:"",text:s,kind:"server",colorCode:a,segments:e})}this.updateCameraAndHud()}getSnapshot(){if(this._cachedSnapshot&&this._cachedSnapshotTick===this.moveTicks)return this._cachedSnapshot;let t=this.buildSnapshot();return this._cachedSnapshot=t,this._cachedSnapshotTick=this.moveTicks,t}getEffectShapes(){let t=new Set,e=e=>{let s=e.dtsFileName;s&&t.add(s);let a=e.subExplosions;if(Array.isArray(a))for(let e of a){if(null==e)continue;let s=this.getDataBlockData(e);s?.dtsFileName&&t.add(s.dtsFileName)}};for(let[,t]of this.initialBlock.dataBlocks){let s=t.data?.explosion;if(null==s)continue;let a=this.getDataBlockData(s);a&&e(a)}return[...t]}stepToTime(t,e=1/0){let s=Math.floor(1e3*(Number.isFinite(t)?Math.max(0,t):0)/i.TICK_DURATION_MS),a=!1;s<this.moveTicks&&(this.reset(),a=!0);let o=this.exhausted,r=0;for(;!this.exhausted&&this.moveTicks<s&&r<e&&this.stepOneMoveTick();)r+=1;if(0===r&&!a&&o===this.exhausted&&this._cachedSnapshot&&this._cachedSnapshotTick===this.moveTicks)return this._cachedSnapshot;let n=this.buildSnapshot();return this._cachedSnapshot=n,this._cachedSnapshotTick=this.moveTicks,n}stepOneMoveTick(){for(;;){let t=this.parser.nextBlock();if(!t)return this.exhausted=!0,!1;if(this.handleBlock(t),t.type===e.BlockTypeMove)return this.moveTicks+=1,this.tickCount=this.moveTicks,this.advanceProjectiles(),this.advanceItems(),this.removeExpiredExplosions(),this.updateCameraAndHud(),!0}}handleBlock(t){if(t.type===e.BlockTypePacket&&this.isPacketData(t.parsed)){let e=t.parsed;this.processControlObject(e.gameState);let s=e.gameState.controlObjectData;if(s){let t=this.getAbsoluteRotation(s);t&&(this.absoluteYaw=t.yaw,this.absolutePitch=t.pitch,this.lastAbsYaw=t.yaw,this.lastAbsPitch=t.pitch)}for(let t of e.events){let e=this.registry.getEventParser(t.classId)?.name;this.processEvent(t,e)}for(let t of e.ghosts)this.processGhostUpdate(t);return}if(t.type===e.BlockTypeInfo&&this.isInfoData(t.parsed)){this.firstPerson=(255&t.parsed.value1)!=0,Number.isFinite(t.parsed.value2)&&(this.latestFov=t.parsed.value2);return}if(t.type===e.BlockTypeMove&&this.isMoveData(t.parsed)){this.absoluteYaw+=t.parsed.yaw??0;let e=2*Math.PI;this.absoluteYaw=(this.absoluteYaw%e+e)%e,this.absolutePitch=(0,o.clamp)(this.absolutePitch+(t.parsed.pitch??0),-o.MAX_PITCH,o.MAX_PITCH)}}buildSnapshot(){let t,e=this.buildEntityList(),s=this.getTimeSec(),a=this._snap,{chatMessages:i,audioEvents:o}=this.buildTimeFilteredEvents(s),r=a&&a.weaponsHudGen===this._weaponsHudGen?a.weaponsHud:{slots:Array.from(this.weaponsHud.slots.entries()).map(([t,e])=>({index:t,ammo:e})),activeIndex:this.weaponsHud.activeIndex},n=a&&a.inventoryHudGen===this._inventoryHudGen?a.inventoryHud:{slots:Array.from(this.inventoryHud.slots.entries()).map(([t,e])=>({slot:t,count:e})),activeSlot:this.inventoryHud.activeSlot},l=a&&a.backpackPackIndex===this.backpackHud.packIndex&&a.backpackActive===this.backpackHud.active&&a.backpackText===this.backpackHud.text?a.backpackHud:this.backpackHud.packIndex>=0?{...this.backpackHud}:null;if(a&&a.teamScoresGen===this._teamScoresGen&&a.rosterGen===this._rosterGen)t=a.teamScores;else{t=this.teamScores.map(t=>({...t}));let e=new Map;for(let{teamId:t}of this.playerRoster.values())t>0&&e.set(t,(e.get(t)??0)+1);for(let s of t)s.playerCount=e.get(s.teamId)??0}return this._snap={teamScoresGen:this._teamScoresGen,rosterGen:this._rosterGen,teamScores:t,weaponsHudGen:this._weaponsHudGen,weaponsHud:r,inventoryHudGen:this._inventoryHudGen,inventoryHud:n,backpackPackIndex:this.backpackHud.packIndex,backpackActive:this.backpackHud.active,backpackText:this.backpackHud.text,backpackHud:l},{timeSec:s,exhausted:this.exhausted,camera:this.camera,entities:e,controlPlayerGhostId:this.controlPlayerGhostId,playerSensorGroup:this.playerSensorGroup,status:this.lastStatus,chatMessages:i,audioEvents:o,weaponsHud:r,backpackHud:l,inventoryHud:n,teamScores:t}}isPacketData(t){return!!t&&"object"==typeof t&&"gameState"in t&&"events"in t&&"ghosts"in t}isMoveData(t){return!!t&&"object"==typeof t&&"yaw"in t}isInfoData(t){return!!t&&"object"==typeof t&&"value1"in t&&"number"==typeof t.value1&&"value2"in t&&"number"==typeof t.value2}}async function l(t){let e=new s.DemoParser(new Uint8Array(t)),{header:a,initialBlock:i}=await e.load(),r=function(t){let e=null,s=null,a=null,i=null,r=null,n=null,l=null;for(let c=0;c<t.length;c++){let h=t[c].split(" ");if(h.length>=3&&h[1]?.endsWith("Game")&&(a=h[1]),"readplayerinfo"!==t[c])continue;let p=t[c+1];if(p){if(p.startsWith("1 ")){let t=p.split(" ");t[2]&&(n=(0,o.stripTaggedStringMarkup)(t[2]).trim());continue}if(p.startsWith("2 ")){let t=p.split(" ");t[1]&&(i=t[1]),t[3]&&(l=t[3]),t[4]&&(e=t[4]);continue}if(p.startsWith("3 ")){let t=p.split(" ");t[1]&&(r=t[1]),t[2]&&(s=t[2])}}}return{missionDisplayName:e,missionType:s,gameClassName:a,serverDisplayName:i,mod:r,recorderName:n,recordingDate:l}}(i.demoValues),l=new n(e);return l.missionDisplayName=r.missionDisplayName,l.missionTypeDisplayName=r.missionType,l.gameClassName=r.gameClassName,l.serverDisplayName=r.serverDisplayName,l.connectedPlayerName=r.recorderName,{source:"demo",duration:a.demoLengthMs/1e3,missionName:i.missionName??null,gameType:r.missionType,serverDisplayName:r.serverDisplayName,recorderName:r.recorderName,recordingDate:r.recordingDate,streamingPlayback:l}}t.s(["createDemoStreamingRecording",()=>l])}]); |