quake2ts 0.0.78 → 0.0.79

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.
@@ -310,6 +310,193 @@ function configStringSize(index) {
310
310
  return CS_MAX_STRING_LENGTH;
311
311
  }
312
312
  var WATERJUMP_CLEAR = 8 | 16 | 32 | 1024;
313
+ var ServerCommand = /* @__PURE__ */ ((ServerCommand2) => {
314
+ ServerCommand2[ServerCommand2["bad"] = 0] = "bad";
315
+ ServerCommand2[ServerCommand2["muzzleflash"] = 1] = "muzzleflash";
316
+ ServerCommand2[ServerCommand2["muzzleflash2"] = 2] = "muzzleflash2";
317
+ ServerCommand2[ServerCommand2["temp_entity"] = 3] = "temp_entity";
318
+ ServerCommand2[ServerCommand2["layout"] = 4] = "layout";
319
+ ServerCommand2[ServerCommand2["inventory"] = 5] = "inventory";
320
+ ServerCommand2[ServerCommand2["nop"] = 6] = "nop";
321
+ ServerCommand2[ServerCommand2["disconnect"] = 7] = "disconnect";
322
+ ServerCommand2[ServerCommand2["reconnect"] = 8] = "reconnect";
323
+ ServerCommand2[ServerCommand2["sound"] = 9] = "sound";
324
+ ServerCommand2[ServerCommand2["print"] = 10] = "print";
325
+ ServerCommand2[ServerCommand2["stufftext"] = 11] = "stufftext";
326
+ ServerCommand2[ServerCommand2["serverdata"] = 12] = "serverdata";
327
+ ServerCommand2[ServerCommand2["configstring"] = 13] = "configstring";
328
+ ServerCommand2[ServerCommand2["spawnbaseline"] = 14] = "spawnbaseline";
329
+ ServerCommand2[ServerCommand2["centerprint"] = 15] = "centerprint";
330
+ ServerCommand2[ServerCommand2["download"] = 16] = "download";
331
+ ServerCommand2[ServerCommand2["playerinfo"] = 17] = "playerinfo";
332
+ ServerCommand2[ServerCommand2["packetentities"] = 18] = "packetentities";
333
+ ServerCommand2[ServerCommand2["deltapacketentities"] = 19] = "deltapacketentities";
334
+ ServerCommand2[ServerCommand2["frame"] = 20] = "frame";
335
+ return ServerCommand2;
336
+ })(ServerCommand || {});
337
+ var TempEntity = /* @__PURE__ */ ((TempEntity2) => {
338
+ TempEntity2[TempEntity2["GUNSHOT"] = 0] = "GUNSHOT";
339
+ TempEntity2[TempEntity2["BLOOD"] = 1] = "BLOOD";
340
+ TempEntity2[TempEntity2["BLASTER"] = 2] = "BLASTER";
341
+ TempEntity2[TempEntity2["RAILTRAIL"] = 3] = "RAILTRAIL";
342
+ TempEntity2[TempEntity2["SHOTGUN"] = 4] = "SHOTGUN";
343
+ TempEntity2[TempEntity2["EXPLOSION1"] = 5] = "EXPLOSION1";
344
+ TempEntity2[TempEntity2["EXPLOSION2"] = 6] = "EXPLOSION2";
345
+ TempEntity2[TempEntity2["ROCKET_EXPLOSION"] = 7] = "ROCKET_EXPLOSION";
346
+ TempEntity2[TempEntity2["GRENADE_EXPLOSION"] = 8] = "GRENADE_EXPLOSION";
347
+ TempEntity2[TempEntity2["SPARKS"] = 9] = "SPARKS";
348
+ TempEntity2[TempEntity2["SPLASH"] = 10] = "SPLASH";
349
+ TempEntity2[TempEntity2["BUBBLETRAIL"] = 11] = "BUBBLETRAIL";
350
+ TempEntity2[TempEntity2["SCREEN_SPARKS"] = 12] = "SCREEN_SPARKS";
351
+ TempEntity2[TempEntity2["SHIELD_SPARKS"] = 13] = "SHIELD_SPARKS";
352
+ TempEntity2[TempEntity2["BULLET_SPARKS"] = 14] = "BULLET_SPARKS";
353
+ TempEntity2[TempEntity2["LASER_SPARKS"] = 15] = "LASER_SPARKS";
354
+ TempEntity2[TempEntity2["PARASITE_ATTACK"] = 16] = "PARASITE_ATTACK";
355
+ TempEntity2[TempEntity2["ROCKET_EXPLOSION_WATER"] = 17] = "ROCKET_EXPLOSION_WATER";
356
+ TempEntity2[TempEntity2["GRENADE_EXPLOSION_WATER"] = 18] = "GRENADE_EXPLOSION_WATER";
357
+ TempEntity2[TempEntity2["MEDIC_CABLE_ATTACK"] = 19] = "MEDIC_CABLE_ATTACK";
358
+ TempEntity2[TempEntity2["BFG_EXPLOSION"] = 20] = "BFG_EXPLOSION";
359
+ TempEntity2[TempEntity2["BFG_BIGEXPLOSION"] = 21] = "BFG_BIGEXPLOSION";
360
+ TempEntity2[TempEntity2["BOSSTPORT"] = 22] = "BOSSTPORT";
361
+ TempEntity2[TempEntity2["BFG_LASER"] = 23] = "BFG_LASER";
362
+ TempEntity2[TempEntity2["GRAPPLE_CABLE"] = 24] = "GRAPPLE_CABLE";
363
+ TempEntity2[TempEntity2["WELDING_SPARKS"] = 25] = "WELDING_SPARKS";
364
+ TempEntity2[TempEntity2["GREENBLOOD"] = 26] = "GREENBLOOD";
365
+ TempEntity2[TempEntity2["BLUEHYPERBLASTER"] = 27] = "BLUEHYPERBLASTER";
366
+ TempEntity2[TempEntity2["PLASMA_EXPLOSION"] = 28] = "PLASMA_EXPLOSION";
367
+ TempEntity2[TempEntity2["TUNNEL_SPARKS"] = 29] = "TUNNEL_SPARKS";
368
+ TempEntity2[TempEntity2["BLASTER2"] = 30] = "BLASTER2";
369
+ TempEntity2[TempEntity2["RAILTRAIL2"] = 31] = "RAILTRAIL2";
370
+ TempEntity2[TempEntity2["FLAME"] = 32] = "FLAME";
371
+ TempEntity2[TempEntity2["LIGHTNING"] = 33] = "LIGHTNING";
372
+ TempEntity2[TempEntity2["DEBUGTRAIL"] = 34] = "DEBUGTRAIL";
373
+ TempEntity2[TempEntity2["PLAIN_EXPLOSION"] = 35] = "PLAIN_EXPLOSION";
374
+ TempEntity2[TempEntity2["FLASHLIGHT"] = 36] = "FLASHLIGHT";
375
+ TempEntity2[TempEntity2["FORCEWALL"] = 37] = "FORCEWALL";
376
+ TempEntity2[TempEntity2["HEATBEAM"] = 38] = "HEATBEAM";
377
+ TempEntity2[TempEntity2["MONSTER_HEATBEAM"] = 39] = "MONSTER_HEATBEAM";
378
+ TempEntity2[TempEntity2["STEAM"] = 40] = "STEAM";
379
+ TempEntity2[TempEntity2["BUBBLETRAIL2"] = 41] = "BUBBLETRAIL2";
380
+ TempEntity2[TempEntity2["MOREBLOOD"] = 42] = "MOREBLOOD";
381
+ TempEntity2[TempEntity2["HEATBEAM_SPARKS"] = 43] = "HEATBEAM_SPARKS";
382
+ TempEntity2[TempEntity2["HEATBEAM_STEAM"] = 44] = "HEATBEAM_STEAM";
383
+ TempEntity2[TempEntity2["CHAINFIST_SMOKE"] = 45] = "CHAINFIST_SMOKE";
384
+ TempEntity2[TempEntity2["ELECTRIC_SPARKS"] = 46] = "ELECTRIC_SPARKS";
385
+ TempEntity2[TempEntity2["TRACKER_EXPLOSION"] = 47] = "TRACKER_EXPLOSION";
386
+ TempEntity2[TempEntity2["TELEPORT_EFFECT"] = 48] = "TELEPORT_EFFECT";
387
+ TempEntity2[TempEntity2["DBALL_GOAL"] = 49] = "DBALL_GOAL";
388
+ TempEntity2[TempEntity2["WIDOWBEAMOUT"] = 50] = "WIDOWBEAMOUT";
389
+ TempEntity2[TempEntity2["NUKEBLAST"] = 51] = "NUKEBLAST";
390
+ TempEntity2[TempEntity2["WIDOWSPLASH"] = 52] = "WIDOWSPLASH";
391
+ TempEntity2[TempEntity2["EXPLOSION1_BIG"] = 53] = "EXPLOSION1_BIG";
392
+ TempEntity2[TempEntity2["EXPLOSION1_NP"] = 54] = "EXPLOSION1_NP";
393
+ TempEntity2[TempEntity2["FLECHETTE"] = 55] = "FLECHETTE";
394
+ return TempEntity2;
395
+ })(TempEntity || {});
396
+ var BinaryStream = class {
397
+ constructor(buffer) {
398
+ if (buffer instanceof Uint8Array) {
399
+ this.view = new DataView(buffer.buffer, buffer.byteOffset, buffer.byteLength);
400
+ } else {
401
+ this.view = new DataView(buffer);
402
+ }
403
+ this.offset = 0;
404
+ this.length = this.view.byteLength;
405
+ }
406
+ getPosition() {
407
+ return this.offset;
408
+ }
409
+ seek(position) {
410
+ if (position < 0 || position > this.length) {
411
+ throw new Error(`Seek out of bounds: ${position} (length: ${this.length})`);
412
+ }
413
+ this.offset = position;
414
+ }
415
+ hasMore() {
416
+ return this.offset < this.length;
417
+ }
418
+ readChar() {
419
+ const value = this.view.getInt8(this.offset);
420
+ this.offset += 1;
421
+ return value;
422
+ }
423
+ readByte() {
424
+ const value = this.view.getUint8(this.offset);
425
+ this.offset += 1;
426
+ return value;
427
+ }
428
+ readShort() {
429
+ const value = this.view.getInt16(this.offset, true);
430
+ this.offset += 2;
431
+ return value;
432
+ }
433
+ readLong() {
434
+ const value = this.view.getInt32(this.offset, true);
435
+ this.offset += 4;
436
+ return value;
437
+ }
438
+ readFloat() {
439
+ const value = this.view.getFloat32(this.offset, true);
440
+ this.offset += 4;
441
+ return value;
442
+ }
443
+ readString() {
444
+ let str = "";
445
+ while (this.offset < this.length) {
446
+ const charCode = this.readChar();
447
+ if (charCode === -1 || charCode === 0) {
448
+ break;
449
+ }
450
+ str += String.fromCharCode(charCode);
451
+ }
452
+ return str;
453
+ }
454
+ readStringLine() {
455
+ let str = "";
456
+ while (this.offset < this.length) {
457
+ const charCode = this.readChar();
458
+ if (charCode === -1 || charCode === 0 || charCode === 10) {
459
+ break;
460
+ }
461
+ str += String.fromCharCode(charCode);
462
+ }
463
+ return str;
464
+ }
465
+ readCoord() {
466
+ return this.readShort() * (1 / 8);
467
+ }
468
+ readAngle() {
469
+ return this.readChar() * (360 / 256);
470
+ }
471
+ readAngle16() {
472
+ return this.readShort() * 360 / 65536;
473
+ }
474
+ readData(length) {
475
+ if (this.offset + length > this.length) {
476
+ throw new Error(`Read out of bounds: ${this.offset + length} (length: ${this.length})`);
477
+ }
478
+ const data = new Uint8Array(this.view.buffer, this.view.byteOffset + this.offset, length);
479
+ this.offset += length;
480
+ return new Uint8Array(data);
481
+ }
482
+ readPos(out) {
483
+ out.x = this.readCoord();
484
+ out.y = this.readCoord();
485
+ out.z = this.readCoord();
486
+ }
487
+ readDir(out) {
488
+ const b = this.readByte();
489
+ if (b >= 162) {
490
+ out.x = 0;
491
+ out.y = 0;
492
+ out.z = 0;
493
+ return;
494
+ }
495
+ out.x = 0;
496
+ out.y = 0;
497
+ out.z = 0;
498
+ }
499
+ };
313
500
 
314
501
  // src/configstrings.ts
315
502
  function assertWithinBounds(index) {
@@ -5455,6 +5642,686 @@ function spawnTrail(context) {
5455
5642
  }
5456
5643
  }
5457
5644
 
5645
+ // src/demo/demoReader.ts
5646
+ var DemoReader = class {
5647
+ constructor(buffer) {
5648
+ this.buffer = buffer;
5649
+ this.view = new DataView(buffer);
5650
+ this.offset = 0;
5651
+ }
5652
+ /**
5653
+ * Checks if there are more blocks to read.
5654
+ */
5655
+ hasMore() {
5656
+ return this.offset < this.buffer.byteLength;
5657
+ }
5658
+ /**
5659
+ * Reads the next message block from the demo file.
5660
+ * Format is [Length (4 bytes)] + [Message Block (Length bytes)].
5661
+ * Returns null if end of file or incomplete block.
5662
+ */
5663
+ readNextBlock() {
5664
+ if (this.offset + 4 > this.buffer.byteLength) {
5665
+ return null;
5666
+ }
5667
+ const length = this.view.getInt32(this.offset, true);
5668
+ this.offset += 4;
5669
+ if (length < 0 || length > 262144) {
5670
+ console.warn(`DemoReader: Invalid block length ${length} at offset ${this.offset - 4}`);
5671
+ return null;
5672
+ }
5673
+ if (this.offset + length > this.buffer.byteLength) {
5674
+ console.warn(`DemoReader: Incomplete block. Expected ${length} bytes, but only ${this.buffer.byteLength - this.offset} remain.`);
5675
+ return null;
5676
+ }
5677
+ const blockData = this.buffer.slice(this.offset, this.offset + length);
5678
+ this.offset += length;
5679
+ return {
5680
+ length,
5681
+ data: new BinaryStream(blockData)
5682
+ };
5683
+ }
5684
+ /**
5685
+ * Resets the reader to the beginning.
5686
+ */
5687
+ reset() {
5688
+ this.offset = 0;
5689
+ }
5690
+ getOffset() {
5691
+ return this.offset;
5692
+ }
5693
+ };
5694
+
5695
+ // src/demo/parser.ts
5696
+ var U_ORIGIN1 = 1 << 0;
5697
+ var U_ORIGIN2 = 1 << 1;
5698
+ var U_ANGLE2 = 1 << 2;
5699
+ var U_ANGLE3 = 1 << 3;
5700
+ var U_FRAME8 = 1 << 4;
5701
+ var U_EVENT = 1 << 5;
5702
+ var U_REMOVE = 1 << 6;
5703
+ var U_MOREBITS1 = 1 << 7;
5704
+ var U_NUMBER16 = 1 << 8;
5705
+ var U_ORIGIN3 = 1 << 9;
5706
+ var U_ANGLE1 = 1 << 10;
5707
+ var U_MODEL = 1 << 11;
5708
+ var U_RENDERFX8 = 1 << 12;
5709
+ var U_EFFECTS8 = 1 << 14;
5710
+ var U_MOREBITS2 = 1 << 15;
5711
+ var U_SKIN8 = 1 << 16;
5712
+ var U_FRAME16 = 1 << 17;
5713
+ var U_RENDERFX16 = 1 << 18;
5714
+ var U_EFFECTS16 = 1 << 19;
5715
+ var U_MODEL2 = 1 << 20;
5716
+ var U_MODEL3 = 1 << 21;
5717
+ var U_MODEL4 = 1 << 22;
5718
+ var U_MOREBITS3 = 1 << 23;
5719
+ var U_OLDORIGIN = 1 << 24;
5720
+ var U_SKIN16 = 1 << 25;
5721
+ var U_SOUND = 1 << 26;
5722
+ var U_SOLID = 1 << 27;
5723
+ var createEmptyEntityState = () => ({
5724
+ number: 0,
5725
+ modelindex: 0,
5726
+ modelindex2: 0,
5727
+ modelindex3: 0,
5728
+ modelindex4: 0,
5729
+ frame: 0,
5730
+ skinnum: 0,
5731
+ effects: 0,
5732
+ renderfx: 0,
5733
+ origin: { x: 0, y: 0, z: 0 },
5734
+ old_origin: { x: 0, y: 0, z: 0 },
5735
+ angles: { x: 0, y: 0, z: 0 },
5736
+ sound: 0,
5737
+ event: 0,
5738
+ solid: 0
5739
+ });
5740
+ var NetworkMessageParser = class {
5741
+ constructor(stream) {
5742
+ this.stream = stream;
5743
+ }
5744
+ parseMessage() {
5745
+ while (this.stream.hasMore()) {
5746
+ const cmd = this.stream.readByte();
5747
+ if (cmd === -1) {
5748
+ break;
5749
+ }
5750
+ switch (cmd) {
5751
+ case ServerCommand.nop:
5752
+ break;
5753
+ case ServerCommand.disconnect:
5754
+ console.log("Server disconnected");
5755
+ break;
5756
+ case ServerCommand.reconnect:
5757
+ console.log("Server reconnect");
5758
+ break;
5759
+ case ServerCommand.print:
5760
+ const printId = this.stream.readByte();
5761
+ const printMsg = this.stream.readString();
5762
+ console.log(`[Server Print ${printId}]: ${printMsg}`);
5763
+ break;
5764
+ case ServerCommand.serverdata:
5765
+ this.parseServerData();
5766
+ break;
5767
+ case ServerCommand.configstring:
5768
+ this.parseConfigString();
5769
+ break;
5770
+ case ServerCommand.spawnbaseline:
5771
+ this.parseSpawnBaseline();
5772
+ break;
5773
+ case ServerCommand.centerprint:
5774
+ const centerMsg = this.stream.readString();
5775
+ console.log(`[Center Print]: ${centerMsg}`);
5776
+ break;
5777
+ case ServerCommand.download:
5778
+ this.parseDownload();
5779
+ break;
5780
+ case ServerCommand.frame:
5781
+ this.parseFrame();
5782
+ break;
5783
+ case ServerCommand.packetentities:
5784
+ this.parsePacketEntities(false);
5785
+ break;
5786
+ case ServerCommand.deltapacketentities:
5787
+ this.parsePacketEntities(true);
5788
+ break;
5789
+ case ServerCommand.stufftext:
5790
+ const text = this.stream.readString();
5791
+ console.log(`[StuffText]: ${text}`);
5792
+ break;
5793
+ case ServerCommand.layout:
5794
+ const layout = this.stream.readString();
5795
+ break;
5796
+ case ServerCommand.inventory:
5797
+ this.parseInventory();
5798
+ break;
5799
+ case ServerCommand.sound:
5800
+ this.parseSound();
5801
+ break;
5802
+ case ServerCommand.muzzleflash:
5803
+ this.parseMuzzleFlash();
5804
+ break;
5805
+ case ServerCommand.muzzleflash2:
5806
+ this.parseMuzzleFlash2();
5807
+ break;
5808
+ case ServerCommand.temp_entity:
5809
+ this.parseTempEntity();
5810
+ break;
5811
+ default:
5812
+ console.warn(`Unknown server command: ${cmd}`);
5813
+ return;
5814
+ }
5815
+ }
5816
+ }
5817
+ parseServerData() {
5818
+ const protocol = this.stream.readLong();
5819
+ const serverCount = this.stream.readLong();
5820
+ const attractLoop = this.stream.readByte();
5821
+ const gameDir = this.stream.readString();
5822
+ const playerNum = this.stream.readShort();
5823
+ const levelName = this.stream.readString();
5824
+ console.log(`Server Data: Protocol ${protocol}, Level ${levelName}, GameDir ${gameDir}`);
5825
+ }
5826
+ parseConfigString() {
5827
+ const index = this.stream.readShort();
5828
+ const str = this.stream.readString();
5829
+ }
5830
+ parseDownload() {
5831
+ const size = this.stream.readShort();
5832
+ const percent = this.stream.readByte();
5833
+ if (size > 0) {
5834
+ this.stream.readData(size);
5835
+ }
5836
+ }
5837
+ parseInventory() {
5838
+ const MAX_ITEMS2 = 256;
5839
+ for (let i = 0; i < MAX_ITEMS2; i++) {
5840
+ this.stream.readShort();
5841
+ }
5842
+ }
5843
+ parseSound() {
5844
+ const flags = this.stream.readByte();
5845
+ const soundNum = this.stream.readByte();
5846
+ if (flags & 1) {
5847
+ this.stream.readByte();
5848
+ }
5849
+ if (flags & 2) {
5850
+ this.stream.readByte();
5851
+ }
5852
+ if (flags & 16) {
5853
+ this.stream.readByte();
5854
+ }
5855
+ if (flags & 8) {
5856
+ this.stream.readShort();
5857
+ }
5858
+ if (flags & 4) {
5859
+ const pos = { x: 0, y: 0, z: 0 };
5860
+ this.stream.readPos(pos);
5861
+ }
5862
+ }
5863
+ parseMuzzleFlash() {
5864
+ const ent = this.stream.readShort();
5865
+ const weapon = this.stream.readByte();
5866
+ }
5867
+ parseMuzzleFlash2() {
5868
+ const ent = this.stream.readShort();
5869
+ const weapon = this.stream.readByte();
5870
+ }
5871
+ parseTempEntity() {
5872
+ const type = this.stream.readByte();
5873
+ const pos = { x: 0, y: 0, z: 0 };
5874
+ const pos2 = { x: 0, y: 0, z: 0 };
5875
+ const dir = { x: 0, y: 0, z: 0 };
5876
+ switch (type) {
5877
+ case TempEntity.BLOOD:
5878
+ this.stream.readPos(pos);
5879
+ this.stream.readDir(dir);
5880
+ break;
5881
+ case TempEntity.GUNSHOT:
5882
+ case TempEntity.SPARKS:
5883
+ case TempEntity.BULLET_SPARKS:
5884
+ this.stream.readPos(pos);
5885
+ this.stream.readDir(dir);
5886
+ break;
5887
+ case TempEntity.SCREEN_SPARKS:
5888
+ case TempEntity.SHIELD_SPARKS:
5889
+ this.stream.readPos(pos);
5890
+ this.stream.readDir(dir);
5891
+ break;
5892
+ case TempEntity.SHOTGUN:
5893
+ this.stream.readPos(pos);
5894
+ this.stream.readDir(dir);
5895
+ break;
5896
+ case TempEntity.SPLASH:
5897
+ this.stream.readByte();
5898
+ this.stream.readPos(pos);
5899
+ this.stream.readDir(dir);
5900
+ this.stream.readByte();
5901
+ break;
5902
+ case TempEntity.LASER_SPARKS:
5903
+ this.stream.readByte();
5904
+ this.stream.readPos(pos);
5905
+ this.stream.readDir(dir);
5906
+ this.stream.readByte();
5907
+ break;
5908
+ case TempEntity.BLUEHYPERBLASTER:
5909
+ this.stream.readPos(pos);
5910
+ this.stream.readPos(dir);
5911
+ break;
5912
+ case TempEntity.BLASTER:
5913
+ this.stream.readPos(pos);
5914
+ this.stream.readDir(dir);
5915
+ break;
5916
+ case TempEntity.RAILTRAIL:
5917
+ this.stream.readPos(pos);
5918
+ this.stream.readPos(pos2);
5919
+ break;
5920
+ case TempEntity.EXPLOSION2:
5921
+ case TempEntity.GRENADE_EXPLOSION:
5922
+ case TempEntity.GRENADE_EXPLOSION_WATER:
5923
+ this.stream.readPos(pos);
5924
+ break;
5925
+ case TempEntity.PLASMA_EXPLOSION:
5926
+ this.stream.readPos(pos);
5927
+ break;
5928
+ case TempEntity.EXPLOSION1:
5929
+ case TempEntity.EXPLOSION1_BIG:
5930
+ case TempEntity.ROCKET_EXPLOSION:
5931
+ case TempEntity.ROCKET_EXPLOSION_WATER:
5932
+ case TempEntity.EXPLOSION1_NP:
5933
+ this.stream.readPos(pos);
5934
+ break;
5935
+ case TempEntity.BFG_EXPLOSION:
5936
+ this.stream.readPos(pos);
5937
+ break;
5938
+ case TempEntity.BFG_BIGEXPLOSION:
5939
+ this.stream.readPos(pos);
5940
+ break;
5941
+ case TempEntity.BFG_LASER:
5942
+ this.stream.readPos(pos);
5943
+ this.stream.readPos(pos2);
5944
+ break;
5945
+ case TempEntity.BUBBLETRAIL:
5946
+ this.stream.readPos(pos);
5947
+ this.stream.readPos(pos2);
5948
+ break;
5949
+ case TempEntity.PARASITE_ATTACK:
5950
+ case TempEntity.MEDIC_CABLE_ATTACK:
5951
+ this.stream.readShort();
5952
+ this.stream.readPos(pos);
5953
+ this.stream.readPos(pos2);
5954
+ break;
5955
+ case TempEntity.BOSSTPORT:
5956
+ this.stream.readPos(pos);
5957
+ break;
5958
+ case TempEntity.GRAPPLE_CABLE:
5959
+ this.stream.readShort();
5960
+ this.stream.readPos(pos);
5961
+ this.stream.readPos(pos2);
5962
+ this.stream.readPos(dir);
5963
+ break;
5964
+ case TempEntity.WELDING_SPARKS:
5965
+ this.stream.readByte();
5966
+ this.stream.readPos(pos);
5967
+ this.stream.readDir(dir);
5968
+ this.stream.readByte();
5969
+ break;
5970
+ case TempEntity.GREENBLOOD:
5971
+ this.stream.readPos(pos);
5972
+ this.stream.readDir(dir);
5973
+ break;
5974
+ case TempEntity.TUNNEL_SPARKS:
5975
+ this.stream.readByte();
5976
+ this.stream.readPos(pos);
5977
+ this.stream.readDir(dir);
5978
+ this.stream.readByte();
5979
+ break;
5980
+ case TempEntity.BLASTER2:
5981
+ case TempEntity.FLECHETTE:
5982
+ this.stream.readPos(pos);
5983
+ this.stream.readDir(dir);
5984
+ break;
5985
+ case TempEntity.LIGHTNING:
5986
+ this.stream.readShort();
5987
+ this.stream.readShort();
5988
+ this.stream.readPos(pos);
5989
+ this.stream.readPos(pos2);
5990
+ break;
5991
+ case TempEntity.DEBUGTRAIL:
5992
+ this.stream.readPos(pos);
5993
+ this.stream.readPos(pos2);
5994
+ break;
5995
+ case TempEntity.PLAIN_EXPLOSION:
5996
+ this.stream.readPos(pos);
5997
+ break;
5998
+ case TempEntity.FLASHLIGHT:
5999
+ this.stream.readPos(pos);
6000
+ this.stream.readShort();
6001
+ break;
6002
+ case TempEntity.FORCEWALL:
6003
+ this.stream.readPos(pos);
6004
+ this.stream.readPos(pos2);
6005
+ this.stream.readByte();
6006
+ break;
6007
+ case TempEntity.HEATBEAM:
6008
+ this.stream.readShort();
6009
+ this.stream.readPos(pos);
6010
+ this.stream.readPos(pos2);
6011
+ this.stream.readPos(dir);
6012
+ break;
6013
+ case TempEntity.MONSTER_HEATBEAM:
6014
+ this.stream.readShort();
6015
+ this.stream.readPos(pos);
6016
+ this.stream.readPos(pos2);
6017
+ this.stream.readPos(dir);
6018
+ break;
6019
+ case TempEntity.HEATBEAM_SPARKS:
6020
+ this.stream.readPos(pos);
6021
+ this.stream.readDir(dir);
6022
+ break;
6023
+ case TempEntity.HEATBEAM_STEAM:
6024
+ this.stream.readPos(pos);
6025
+ this.stream.readDir(dir);
6026
+ break;
6027
+ case TempEntity.STEAM:
6028
+ const steamId = this.stream.readShort();
6029
+ if (steamId !== -1) {
6030
+ this.stream.readByte();
6031
+ this.stream.readPos(pos);
6032
+ this.stream.readDir(dir);
6033
+ this.stream.readByte();
6034
+ this.stream.readShort();
6035
+ this.stream.readLong();
6036
+ } else {
6037
+ this.stream.readByte();
6038
+ this.stream.readPos(pos);
6039
+ this.stream.readDir(dir);
6040
+ this.stream.readByte();
6041
+ this.stream.readShort();
6042
+ }
6043
+ break;
6044
+ case TempEntity.BUBBLETRAIL2:
6045
+ this.stream.readPos(pos);
6046
+ this.stream.readPos(pos2);
6047
+ break;
6048
+ case TempEntity.MOREBLOOD:
6049
+ this.stream.readPos(pos);
6050
+ this.stream.readDir(dir);
6051
+ break;
6052
+ case TempEntity.CHAINFIST_SMOKE:
6053
+ this.stream.readPos(pos);
6054
+ break;
6055
+ case TempEntity.ELECTRIC_SPARKS:
6056
+ this.stream.readPos(pos);
6057
+ this.stream.readDir(dir);
6058
+ break;
6059
+ case TempEntity.TRACKER_EXPLOSION:
6060
+ this.stream.readPos(pos);
6061
+ break;
6062
+ case TempEntity.TELEPORT_EFFECT:
6063
+ case TempEntity.DBALL_GOAL:
6064
+ this.stream.readPos(pos);
6065
+ break;
6066
+ case TempEntity.WIDOWBEAMOUT:
6067
+ const wbId = this.stream.readShort();
6068
+ this.stream.readPos(pos);
6069
+ break;
6070
+ case TempEntity.NUKEBLAST:
6071
+ this.stream.readPos(pos);
6072
+ break;
6073
+ case TempEntity.WIDOWSPLASH:
6074
+ this.stream.readPos(pos);
6075
+ break;
6076
+ default:
6077
+ console.warn(`CL_ParseTEnt: bad type ${type}`);
6078
+ break;
6079
+ }
6080
+ }
6081
+ parseSpawnBaseline() {
6082
+ const bits = this.parseEntityBits();
6083
+ this.parseDelta(createEmptyEntityState(), createEmptyEntityState(), bits.number, bits.bits);
6084
+ }
6085
+ parseFrame() {
6086
+ const serverFrame = this.stream.readLong();
6087
+ const deltaFrame = this.stream.readLong();
6088
+ const surpressCount = this.stream.readByte();
6089
+ const areaBytes = this.stream.readByte();
6090
+ this.stream.readData(areaBytes);
6091
+ const piCmd = this.stream.readByte();
6092
+ if (piCmd !== ServerCommand.playerinfo) {
6093
+ throw new Error(`Expected svc_playerinfo after svc_frame, got ${piCmd}`);
6094
+ }
6095
+ this.parsePlayerState();
6096
+ const peCmd = this.stream.readByte();
6097
+ if (peCmd !== ServerCommand.packetentities && peCmd !== ServerCommand.deltapacketentities) {
6098
+ throw new Error(`Expected svc_packetentities after svc_playerinfo, got ${peCmd}`);
6099
+ }
6100
+ this.parsePacketEntities(peCmd === ServerCommand.deltapacketentities);
6101
+ }
6102
+ parsePlayerState() {
6103
+ const flags = this.stream.readShort();
6104
+ if (flags & 1) this.stream.readByte();
6105
+ if (flags & 2) {
6106
+ this.stream.readShort();
6107
+ this.stream.readShort();
6108
+ this.stream.readShort();
6109
+ }
6110
+ if (flags & 4) {
6111
+ this.stream.readShort();
6112
+ this.stream.readShort();
6113
+ this.stream.readShort();
6114
+ }
6115
+ if (flags & 8) this.stream.readByte();
6116
+ if (flags & 16) this.stream.readByte();
6117
+ if (flags & 32) this.stream.readShort();
6118
+ if (flags & 64) {
6119
+ this.stream.readShort();
6120
+ this.stream.readShort();
6121
+ this.stream.readShort();
6122
+ }
6123
+ if (flags & 128) {
6124
+ this.stream.readChar();
6125
+ this.stream.readChar();
6126
+ this.stream.readChar();
6127
+ }
6128
+ if (flags & 256) {
6129
+ this.stream.readAngle16();
6130
+ this.stream.readAngle16();
6131
+ this.stream.readAngle16();
6132
+ }
6133
+ if (flags & 512) {
6134
+ this.stream.readChar();
6135
+ this.stream.readChar();
6136
+ this.stream.readChar();
6137
+ }
6138
+ if (flags & 4096) this.stream.readByte();
6139
+ if (flags & 8192) {
6140
+ this.stream.readByte();
6141
+ this.stream.readChar();
6142
+ this.stream.readChar();
6143
+ this.stream.readChar();
6144
+ this.stream.readChar();
6145
+ this.stream.readChar();
6146
+ this.stream.readChar();
6147
+ }
6148
+ if (flags & 1024) {
6149
+ this.stream.readByte();
6150
+ this.stream.readByte();
6151
+ this.stream.readByte();
6152
+ this.stream.readByte();
6153
+ }
6154
+ if (flags & 2048) this.stream.readByte();
6155
+ if (flags & 16384) this.stream.readByte();
6156
+ const statbits = this.stream.readLong();
6157
+ for (let i = 0; i < 32; i++) {
6158
+ if (statbits & 1 << i) {
6159
+ this.stream.readShort();
6160
+ }
6161
+ }
6162
+ }
6163
+ parsePacketEntities(delta) {
6164
+ while (true) {
6165
+ const bits = this.parseEntityBits();
6166
+ if (bits.number === 0) {
6167
+ break;
6168
+ }
6169
+ this.parseDelta(createEmptyEntityState(), createEmptyEntityState(), bits.number, bits.bits);
6170
+ }
6171
+ }
6172
+ parseEntityBits() {
6173
+ let total = this.stream.readByte();
6174
+ if (total & U_MOREBITS1) {
6175
+ total |= this.stream.readByte() << 8;
6176
+ }
6177
+ if (total & U_MOREBITS2) {
6178
+ total |= this.stream.readByte() << 16;
6179
+ }
6180
+ if (total & U_MOREBITS3) {
6181
+ total |= this.stream.readByte() << 24;
6182
+ }
6183
+ let number;
6184
+ if (total & U_NUMBER16) {
6185
+ number = this.stream.readShort();
6186
+ } else {
6187
+ number = this.stream.readByte();
6188
+ }
6189
+ return { number, bits: total };
6190
+ }
6191
+ parseDelta(from, to, number, bits) {
6192
+ to.number = from.number;
6193
+ to.modelindex = from.modelindex;
6194
+ to.modelindex2 = from.modelindex2;
6195
+ to.modelindex3 = from.modelindex3;
6196
+ to.modelindex4 = from.modelindex4;
6197
+ to.frame = from.frame;
6198
+ to.skinnum = from.skinnum;
6199
+ to.effects = from.effects;
6200
+ to.renderfx = from.renderfx;
6201
+ to.origin.x = from.origin.x;
6202
+ to.origin.y = from.origin.y;
6203
+ to.origin.z = from.origin.z;
6204
+ to.old_origin.x = from.origin.x;
6205
+ to.old_origin.y = from.origin.y;
6206
+ to.old_origin.z = from.origin.z;
6207
+ to.angles.x = from.angles.x;
6208
+ to.angles.y = from.angles.y;
6209
+ to.angles.z = from.angles.z;
6210
+ to.sound = from.sound;
6211
+ to.event = from.event;
6212
+ to.solid = from.solid;
6213
+ to.number = number;
6214
+ if (bits & U_MODEL) to.modelindex = this.stream.readByte();
6215
+ if (bits & U_MODEL2) to.modelindex2 = this.stream.readByte();
6216
+ if (bits & U_MODEL3) to.modelindex3 = this.stream.readByte();
6217
+ if (bits & U_MODEL4) to.modelindex4 = this.stream.readByte();
6218
+ if (bits & U_FRAME8) to.frame = this.stream.readByte();
6219
+ if (bits & U_FRAME16) to.frame = this.stream.readShort();
6220
+ if (bits & U_SKIN8 && bits & U_SKIN16) {
6221
+ to.skinnum = this.stream.readLong();
6222
+ } else if (bits & U_SKIN8) {
6223
+ to.skinnum = this.stream.readByte();
6224
+ } else if (bits & U_SKIN16) {
6225
+ to.skinnum = this.stream.readShort();
6226
+ }
6227
+ if (bits & U_EFFECTS8 && bits & U_EFFECTS16) {
6228
+ to.effects = this.stream.readLong();
6229
+ } else if (bits & U_EFFECTS8) {
6230
+ to.effects = this.stream.readByte();
6231
+ } else if (bits & U_EFFECTS16) {
6232
+ to.effects = this.stream.readShort();
6233
+ }
6234
+ if (bits & U_RENDERFX8 && bits & U_RENDERFX16) {
6235
+ to.renderfx = this.stream.readLong();
6236
+ } else if (bits & U_RENDERFX8) {
6237
+ to.renderfx = this.stream.readByte();
6238
+ } else if (bits & U_RENDERFX16) {
6239
+ to.renderfx = this.stream.readShort();
6240
+ }
6241
+ if (bits & U_ORIGIN1) to.origin.x = this.stream.readCoord();
6242
+ if (bits & U_ORIGIN2) to.origin.y = this.stream.readCoord();
6243
+ if (bits & U_ORIGIN3) to.origin.z = this.stream.readCoord();
6244
+ if (bits & U_ANGLE1) to.angles.x = this.stream.readAngle();
6245
+ if (bits & U_ANGLE2) to.angles.y = this.stream.readAngle();
6246
+ if (bits & U_ANGLE3) to.angles.z = this.stream.readAngle();
6247
+ if (bits & U_OLDORIGIN) {
6248
+ this.stream.readPos(to.old_origin);
6249
+ }
6250
+ if (bits & U_SOUND) to.sound = this.stream.readByte();
6251
+ if (bits & U_EVENT) {
6252
+ to.event = this.stream.readByte();
6253
+ } else {
6254
+ to.event = 0;
6255
+ }
6256
+ if (bits & U_SOLID) to.solid = this.stream.readShort();
6257
+ }
6258
+ };
6259
+
6260
+ // src/demo/playback.ts
6261
+ var PlaybackState = /* @__PURE__ */ ((PlaybackState2) => {
6262
+ PlaybackState2[PlaybackState2["Stopped"] = 0] = "Stopped";
6263
+ PlaybackState2[PlaybackState2["Playing"] = 1] = "Playing";
6264
+ PlaybackState2[PlaybackState2["Paused"] = 2] = "Paused";
6265
+ PlaybackState2[PlaybackState2["Finished"] = 3] = "Finished";
6266
+ return PlaybackState2;
6267
+ })(PlaybackState || {});
6268
+ var DemoPlaybackController = class {
6269
+ // ms (10Hz default)
6270
+ constructor() {
6271
+ this.reader = null;
6272
+ this.state = 0 /* Stopped */;
6273
+ this.playbackSpeed = 1;
6274
+ // Timing
6275
+ this.accumulatedTime = 0;
6276
+ this.frameDuration = 100;
6277
+ }
6278
+ loadDemo(buffer) {
6279
+ this.reader = new DemoReader(buffer);
6280
+ this.state = 0 /* Stopped */;
6281
+ this.accumulatedTime = 0;
6282
+ }
6283
+ play() {
6284
+ if (this.reader) {
6285
+ this.state = 1 /* Playing */;
6286
+ }
6287
+ }
6288
+ pause() {
6289
+ if (this.state === 1 /* Playing */) {
6290
+ this.state = 2 /* Paused */;
6291
+ }
6292
+ }
6293
+ stop() {
6294
+ this.state = 0 /* Stopped */;
6295
+ if (this.reader) {
6296
+ this.reader.reset();
6297
+ }
6298
+ this.accumulatedTime = 0;
6299
+ }
6300
+ update(dt) {
6301
+ if (this.state !== 1 /* Playing */ || !this.reader) {
6302
+ return;
6303
+ }
6304
+ this.accumulatedTime += dt * 1e3 * this.playbackSpeed;
6305
+ while (this.accumulatedTime >= this.frameDuration) {
6306
+ if (!this.reader.hasMore()) {
6307
+ this.state = 3 /* Finished */;
6308
+ return;
6309
+ }
6310
+ const block = this.reader.readNextBlock();
6311
+ if (!block) {
6312
+ this.state = 3 /* Finished */;
6313
+ return;
6314
+ }
6315
+ const parser = new NetworkMessageParser(block.data);
6316
+ parser.parseMessage();
6317
+ this.accumulatedTime -= this.frameDuration;
6318
+ }
6319
+ }
6320
+ getState() {
6321
+ return this.state;
6322
+ }
6323
+ };
6324
+
5458
6325
  // src/index.ts
5459
6326
  function createEngine(imports) {
5460
6327
  return {
@@ -5492,6 +6359,8 @@ export {
5492
6359
  ConfigStringRegistry,
5493
6360
  Cvar,
5494
6361
  CvarRegistry,
6362
+ DemoPlaybackController,
6363
+ DemoReader,
5495
6364
  EngineHost,
5496
6365
  EngineRuntime,
5497
6366
  FixedTimestepLoop,
@@ -5513,6 +6382,7 @@ export {
5513
6382
  Md3Pipeline,
5514
6383
  Md3SurfaceMesh,
5515
6384
  MusicSystem,
6385
+ NetworkMessageParser,
5516
6386
  PARTICLE_FRAGMENT_SHADER,
5517
6387
  PARTICLE_VERTEX_SHADER,
5518
6388
  PakArchive,
@@ -5523,6 +6393,7 @@ export {
5523
6393
  PakValidator,
5524
6394
  ParticleRenderer,
5525
6395
  ParticleSystem,
6396
+ PlaybackState,
5526
6397
  RERELEASE_KNOWN_PAKS,
5527
6398
  SKYBOX_FRAGMENT_SHADER,
5528
6399
  SKYBOX_VERTEX_SHADER,