quake2ts 0.0.288 → 0.0.289
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/package.json +1 -1
- package/packages/client/dist/browser/index.global.js +13 -13
- package/packages/client/dist/browser/index.global.js.map +1 -1
- package/packages/client/dist/cjs/index.cjs +554 -2
- package/packages/client/dist/cjs/index.cjs.map +1 -1
- package/packages/client/dist/esm/index.js +554 -2
- package/packages/client/dist/esm/index.js.map +1 -1
- package/packages/client/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/engine/dist/browser/index.global.js +16 -16
- package/packages/engine/dist/browser/index.global.js.map +1 -1
- package/packages/engine/dist/cjs/index.cjs +327 -0
- package/packages/engine/dist/cjs/index.cjs.map +1 -1
- package/packages/engine/dist/esm/index.js +327 -0
- package/packages/engine/dist/esm/index.js.map +1 -1
- package/packages/engine/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/game/dist/browser/index.global.js +3 -3
- package/packages/game/dist/browser/index.global.js.map +1 -1
- package/packages/game/dist/cjs/index.cjs +492 -1
- package/packages/game/dist/cjs/index.cjs.map +1 -1
- package/packages/game/dist/esm/index.js +492 -1
- package/packages/game/dist/esm/index.js.map +1 -1
- package/packages/game/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/server/dist/index.cjs +54 -11
- package/packages/server/dist/index.d.cts +6 -1
- package/packages/server/dist/index.d.ts +6 -1
- package/packages/server/dist/index.js +56 -13
- package/packages/shared/dist/browser/index.global.js +1 -1
- package/packages/shared/dist/browser/index.global.js.map +1 -1
- package/packages/shared/dist/cjs/index.cjs +509 -0
- package/packages/shared/dist/cjs/index.cjs.map +1 -1
- package/packages/shared/dist/esm/index.js +507 -0
- package/packages/shared/dist/esm/index.js.map +1 -1
- package/packages/shared/dist/tsconfig.tsbuildinfo +1 -1
- package/packages/shared/dist/types/net/index.d.ts +1 -0
- package/packages/shared/dist/types/net/index.d.ts.map +1 -1
- package/packages/shared/dist/types/protocol/crc.d.ts +5 -0
- package/packages/shared/dist/types/protocol/crc.d.ts.map +1 -0
- package/packages/shared/dist/types/protocol/index.d.ts +1 -0
- package/packages/shared/dist/types/protocol/index.d.ts.map +1 -1
- package/packages/tools/dist/tsconfig.tsbuildinfo +1 -1
|
@@ -446,7 +446,7 @@ function G_SetPowerupStat(stats, powerupId, val) {
|
|
|
446
446
|
if (safeVal < 0) safeVal = 0;
|
|
447
447
|
setCompressedInteger(stats, 41, index, safeVal, NUM_BITS_FOR_POWERUP);
|
|
448
448
|
}
|
|
449
|
-
var __defProp2, __export2, ZERO_VEC3, STOP_EPSILON, DEG_TO_RAD, PITCH, YAW, ROLL, DEG2RAD_FACTOR, RAD2DEG_FACTOR, STATE_SIZE, MIDDLE_WORD, MATRIX_A, UPPER_MASK, LOWER_MASK, TWO_POW_32, MersenneTwister19937, RandomGenerator, CONTENTS_SOLID, CONTENTS_WINDOW, CONTENTS_AUX, CONTENTS_LAVA, CONTENTS_SLIME, CONTENTS_WATER, CONTENTS_MIST, CONTENTS_NO_WATERJUMP, CONTENTS_PROJECTILECLIP, CONTENTS_AREAPORTAL, CONTENTS_PLAYERCLIP, CONTENTS_MONSTERCLIP, CONTENTS_CURRENT_0, CONTENTS_CURRENT_90, CONTENTS_CURRENT_180, CONTENTS_CURRENT_270, CONTENTS_CURRENT_UP, CONTENTS_CURRENT_DOWN, CONTENTS_ORIGIN, CONTENTS_MONSTER, CONTENTS_DEADMONSTER, CONTENTS_DETAIL, CONTENTS_TRANSLUCENT, CONTENTS_LADDER, CONTENTS_PLAYER, CONTENTS_PROJECTILE, SURF_LIGHT, SURF_SLICK, SURF_SKY, SURF_WARP, SURF_TRANS33, SURF_TRANS66, SURF_FLOWING, SURF_NODRAW, SURF_ALPHATEST, SURF_N64_UV, SURF_N64_SCROLL_X, SURF_N64_SCROLL_Y, SURF_N64_SCROLL_FLIP, MASK_SOLID, MASK_PLAYERSOLID, MASK_DEADSOLID, MASK_MONSTERSOLID, MASK_WATER, MASK_OPAQUE, MASK_SHOT, MASK_CURRENT, MASK_BLOCK_SIGHT, MASK_NAV_SOLID, MASK_LADDER_NAV_SOLID, MASK_WALK_NAV_SOLID, MASK_PROJECTILE, MAX_CHECKCOUNT, CvarFlags, MAX_CLIENTS, MAX_LIGHTSTYLES, MAX_MODELS, MAX_SOUNDS, MAX_IMAGES, MAX_ITEMS, MAX_GENERAL, MAX_SHADOW_LIGHTS, MAX_WHEEL_ITEMS, ConfigStringIndex, MAX_CONFIGSTRINGS, replay_exports, WaterLevel, WATERJUMP_CLEAR, ServerCommand, TempEntity, MZ_BLASTER, MZ_MACHINEGUN, MZ_SHOTGUN, MZ_CHAINGUN1, MZ_RAILGUN, MZ_ROCKET, MZ_GRENADE, MZ_SSHOTGUN, MZ_BFG, MZ_HYPERBLASTER, PowerupId, PlayerStat, AMMO_MAX, NUM_BITS_FOR_AMMO, NUM_AMMO_STATS, POWERUP_MAX, NUM_BITS_FOR_POWERUP, NUM_POWERUP_STATS, POWERUP_STAT_MAP, RenderFx, entityFlags_exports, U_NUMBER, U_MODEL, U_SOUND, U_ORIGIN1, U_ORIGIN2, U_ORIGIN3, U_ANGLE1, U_ANGLE2, U_ANGLE3, U_FRAME, U_SKIN, U_EFFECTS, U_RENDERFX, U_SOLID, U_EVENT, U_MOREBITS, U_MODEL2, U_MODEL3, U_MODEL4, U_REMOVE, FRAMETIME, MASK_WATER2, WaterLevel3, categorizePosition2, checkWater, applyPmove, WeaponId, AmmoType, AMMO_TYPE_COUNT, AmmoItemId, WEAPON_WHEEL_ORDER;
|
|
449
|
+
var __defProp2, __export2, ZERO_VEC3, STOP_EPSILON, DEG_TO_RAD, PITCH, YAW, ROLL, DEG2RAD_FACTOR, RAD2DEG_FACTOR, ANORMS, STATE_SIZE, MIDDLE_WORD, MATRIX_A, UPPER_MASK, LOWER_MASK, TWO_POW_32, MersenneTwister19937, RandomGenerator, CONTENTS_SOLID, CONTENTS_WINDOW, CONTENTS_AUX, CONTENTS_LAVA, CONTENTS_SLIME, CONTENTS_WATER, CONTENTS_MIST, CONTENTS_NO_WATERJUMP, CONTENTS_PROJECTILECLIP, CONTENTS_AREAPORTAL, CONTENTS_PLAYERCLIP, CONTENTS_MONSTERCLIP, CONTENTS_CURRENT_0, CONTENTS_CURRENT_90, CONTENTS_CURRENT_180, CONTENTS_CURRENT_270, CONTENTS_CURRENT_UP, CONTENTS_CURRENT_DOWN, CONTENTS_ORIGIN, CONTENTS_MONSTER, CONTENTS_DEADMONSTER, CONTENTS_DETAIL, CONTENTS_TRANSLUCENT, CONTENTS_LADDER, CONTENTS_PLAYER, CONTENTS_PROJECTILE, SURF_LIGHT, SURF_SLICK, SURF_SKY, SURF_WARP, SURF_TRANS33, SURF_TRANS66, SURF_FLOWING, SURF_NODRAW, SURF_ALPHATEST, SURF_N64_UV, SURF_N64_SCROLL_X, SURF_N64_SCROLL_Y, SURF_N64_SCROLL_FLIP, MASK_SOLID, MASK_PLAYERSOLID, MASK_DEADSOLID, MASK_MONSTERSOLID, MASK_WATER, MASK_OPAQUE, MASK_SHOT, MASK_CURRENT, MASK_BLOCK_SIGHT, MASK_NAV_SOLID, MASK_LADDER_NAV_SOLID, MASK_WALK_NAV_SOLID, MASK_PROJECTILE, MAX_CHECKCOUNT, CvarFlags, MAX_CLIENTS, MAX_LIGHTSTYLES, MAX_MODELS, MAX_SOUNDS, MAX_IMAGES, MAX_ITEMS, MAX_GENERAL, MAX_SHADOW_LIGHTS, MAX_WHEEL_ITEMS, ConfigStringIndex, MAX_CONFIGSTRINGS, replay_exports, WaterLevel, WATERJUMP_CLEAR, ServerCommand, TempEntity, MZ_BLASTER, MZ_MACHINEGUN, MZ_SHOTGUN, MZ_CHAINGUN1, MZ_RAILGUN, MZ_ROCKET, MZ_GRENADE, MZ_SSHOTGUN, MZ_BFG, MZ_HYPERBLASTER, PowerupId, PlayerStat, AMMO_MAX, NUM_BITS_FOR_AMMO, NUM_AMMO_STATS, POWERUP_MAX, NUM_BITS_FOR_POWERUP, NUM_POWERUP_STATS, POWERUP_STAT_MAP, RenderFx, entityFlags_exports, U_NUMBER, U_MODEL, U_SOUND, U_ORIGIN1, U_ORIGIN2, U_ORIGIN3, U_ANGLE1, U_ANGLE2, U_ANGLE3, U_FRAME, U_SKIN, U_EFFECTS, U_RENDERFX, U_SOLID, U_EVENT, U_MOREBITS, U_MODEL2, U_MODEL3, U_MODEL4, U_REMOVE, FRAMETIME, MASK_WATER2, WaterLevel3, categorizePosition2, checkWater, applyPmove, BinaryWriter, _NetChan, WeaponId, AmmoType, AMMO_TYPE_COUNT, AmmoItemId, WEAPON_WHEEL_ORDER;
|
|
450
450
|
var init_esm = __esm({
|
|
451
451
|
"../shared/dist/esm/index.js"() {
|
|
452
452
|
"use strict";
|
|
@@ -463,6 +463,170 @@ var init_esm = __esm({
|
|
|
463
463
|
ROLL = 2;
|
|
464
464
|
DEG2RAD_FACTOR = Math.PI / 180;
|
|
465
465
|
RAD2DEG_FACTOR = 180 / Math.PI;
|
|
466
|
+
ANORMS = [
|
|
467
|
+
[-0.525731, 0, 0.850651],
|
|
468
|
+
[-0.442863, 0.238856, 0.864188],
|
|
469
|
+
[-0.295242, 0, 0.955423],
|
|
470
|
+
[-0.309017, 0.5, 0.809017],
|
|
471
|
+
[-0.16246, 0.262866, 0.951056],
|
|
472
|
+
[0, 0, 1],
|
|
473
|
+
[0, 0.850651, 0.525731],
|
|
474
|
+
[-0.147621, 0.716567, 0.681718],
|
|
475
|
+
[0.147621, 0.716567, 0.681718],
|
|
476
|
+
[0, 0.525731, 0.850651],
|
|
477
|
+
[0.309017, 0.5, 0.809017],
|
|
478
|
+
[0.525731, 0, 0.850651],
|
|
479
|
+
[0.295242, 0, 0.955423],
|
|
480
|
+
[0.442863, 0.238856, 0.864188],
|
|
481
|
+
[0.16246, 0.262866, 0.951056],
|
|
482
|
+
[-0.681718, 0.147621, 0.716567],
|
|
483
|
+
[-0.809017, 0.309017, 0.5],
|
|
484
|
+
[-0.587785, 0.425325, 0.688191],
|
|
485
|
+
[-0.850651, 0.525731, 0],
|
|
486
|
+
[-0.864188, 0.442863, 0.238856],
|
|
487
|
+
[-0.716567, 0.681718, 0.147621],
|
|
488
|
+
[-0.688191, 0.587785, 0.425325],
|
|
489
|
+
[-0.5, 0.809017, 0.309017],
|
|
490
|
+
[-0.238856, 0.864188, 0.442863],
|
|
491
|
+
[-0.425325, 0.688191, 0.587785],
|
|
492
|
+
[-0.716567, 0.681718, -0.147621],
|
|
493
|
+
[-0.5, 0.809017, -0.309017],
|
|
494
|
+
[-0.525731, 0.850651, 0],
|
|
495
|
+
[0, 0.850651, -0.525731],
|
|
496
|
+
[-0.238856, 0.864188, -0.442863],
|
|
497
|
+
[0, 0.955423, -0.295242],
|
|
498
|
+
[-0.262866, 0.951056, -0.16246],
|
|
499
|
+
[0, 1, 0],
|
|
500
|
+
[0, 0.955423, 0.295242],
|
|
501
|
+
[-0.262866, 0.951056, 0.16246],
|
|
502
|
+
[0.238856, 0.864188, 0.442863],
|
|
503
|
+
[0.262866, 0.951056, 0.16246],
|
|
504
|
+
[0.5, 0.809017, 0.309017],
|
|
505
|
+
[0.238856, 0.864188, -0.442863],
|
|
506
|
+
[0.262866, 0.951056, -0.16246],
|
|
507
|
+
[0.5, 0.809017, -0.309017],
|
|
508
|
+
[0.850651, 0.525731, 0],
|
|
509
|
+
[0.716567, 0.681718, 0.147621],
|
|
510
|
+
[0.716567, 0.681718, -0.147621],
|
|
511
|
+
[0.525731, 0.850651, 0],
|
|
512
|
+
[0.425325, 0.688191, 0.587785],
|
|
513
|
+
[0.864188, 0.442863, 0.238856],
|
|
514
|
+
[0.688191, 0.587785, 0.425325],
|
|
515
|
+
[0.809017, 0.309017, 0.5],
|
|
516
|
+
[0.681718, 0.147621, 0.716567],
|
|
517
|
+
[0.587785, 0.425325, 0.688191],
|
|
518
|
+
[0.955423, 0.295242, 0],
|
|
519
|
+
[1, 0, 0],
|
|
520
|
+
[0.951056, 0.16246, 0.262866],
|
|
521
|
+
[0.850651, -0.525731, 0],
|
|
522
|
+
[0.955423, -0.295242, 0],
|
|
523
|
+
[0.864188, -0.442863, 0.238856],
|
|
524
|
+
[0.951056, -0.16246, 0.262866],
|
|
525
|
+
[0.809017, -0.309017, 0.5],
|
|
526
|
+
[0.681718, -0.147621, 0.716567],
|
|
527
|
+
[0.850651, 0, 0.525731],
|
|
528
|
+
[0.864188, 0.442863, -0.238856],
|
|
529
|
+
[0.809017, 0.309017, -0.5],
|
|
530
|
+
[0.951056, 0.16246, -0.262866],
|
|
531
|
+
[0.525731, 0, -0.850651],
|
|
532
|
+
[0.681718, 0.147621, -0.716567],
|
|
533
|
+
[0.681718, -0.147621, -0.716567],
|
|
534
|
+
[0.850651, 0, -0.525731],
|
|
535
|
+
[0.809017, -0.309017, -0.5],
|
|
536
|
+
[0.864188, -0.442863, -0.238856],
|
|
537
|
+
[0.951056, -0.16246, -0.262866],
|
|
538
|
+
[0.147621, 0.716567, -0.681718],
|
|
539
|
+
[0.309017, 0.5, -0.809017],
|
|
540
|
+
[0.425325, 0.688191, -0.587785],
|
|
541
|
+
[0.442863, 0.238856, -0.864188],
|
|
542
|
+
[0.587785, 0.425325, -0.688191],
|
|
543
|
+
[0.688191, 0.587785, -0.425325],
|
|
544
|
+
[-0.147621, 0.716567, -0.681718],
|
|
545
|
+
[-0.309017, 0.5, -0.809017],
|
|
546
|
+
[0, 0.525731, -0.850651],
|
|
547
|
+
[-0.525731, 0, -0.850651],
|
|
548
|
+
[-0.442863, 0.238856, -0.864188],
|
|
549
|
+
[-0.295242, 0, -0.955423],
|
|
550
|
+
[-0.16246, 0.262866, -0.951056],
|
|
551
|
+
[0, 0, -1],
|
|
552
|
+
[0.295242, 0, -0.955423],
|
|
553
|
+
[0.16246, 0.262866, -0.951056],
|
|
554
|
+
[-0.442863, -0.238856, -0.864188],
|
|
555
|
+
[-0.309017, -0.5, -0.809017],
|
|
556
|
+
[-0.16246, -0.262866, -0.951056],
|
|
557
|
+
[0, -0.850651, -0.525731],
|
|
558
|
+
[-0.147621, -0.716567, -0.681718],
|
|
559
|
+
[0.147621, -0.716567, -0.681718],
|
|
560
|
+
[0, -0.525731, -0.850651],
|
|
561
|
+
[0.309017, -0.5, -0.809017],
|
|
562
|
+
[0.442863, -0.238856, -0.864188],
|
|
563
|
+
[0.16246, -0.262866, -0.951056],
|
|
564
|
+
[0.238856, -0.864188, -0.442863],
|
|
565
|
+
[0.5, -0.809017, -0.309017],
|
|
566
|
+
[0.425325, -0.688191, -0.587785],
|
|
567
|
+
[0.716567, -0.681718, -0.147621],
|
|
568
|
+
[0.688191, -0.587785, -0.425325],
|
|
569
|
+
[0.587785, -0.425325, -0.688191],
|
|
570
|
+
[0, -0.955423, -0.295242],
|
|
571
|
+
[0, -1, 0],
|
|
572
|
+
[0.262866, -0.951056, -0.16246],
|
|
573
|
+
[0, -0.850651, 0.525731],
|
|
574
|
+
[0, -0.955423, 0.295242],
|
|
575
|
+
[0.238856, -0.864188, 0.442863],
|
|
576
|
+
[0.262866, -0.951056, 0.16246],
|
|
577
|
+
[0.5, -0.809017, 0.309017],
|
|
578
|
+
[0.716567, -0.681718, 0.147621],
|
|
579
|
+
[0.525731, -0.850651, 0],
|
|
580
|
+
[-0.238856, -0.864188, -0.442863],
|
|
581
|
+
[-0.5, -0.809017, -0.309017],
|
|
582
|
+
[-0.262866, -0.951056, -0.16246],
|
|
583
|
+
[-0.850651, -0.525731, 0],
|
|
584
|
+
[-0.716567, -0.681718, -0.147621],
|
|
585
|
+
[-0.716567, -0.681718, 0.147621],
|
|
586
|
+
[-0.525731, -0.850651, 0],
|
|
587
|
+
[-0.5, -0.809017, 0.309017],
|
|
588
|
+
[-0.238856, -0.864188, 0.442863],
|
|
589
|
+
[-0.262866, -0.951056, 0.16246],
|
|
590
|
+
[-0.864188, -0.442863, 0.238856],
|
|
591
|
+
[-0.809017, -0.309017, 0.5],
|
|
592
|
+
[-0.688191, -0.587785, 0.425325],
|
|
593
|
+
[-0.681718, -0.147621, 0.716567],
|
|
594
|
+
[-0.442863, -0.238856, 0.864188],
|
|
595
|
+
[-0.587785, -0.425325, 0.688191],
|
|
596
|
+
[-0.309017, -0.5, 0.809017],
|
|
597
|
+
[-0.147621, -0.716567, 0.681718],
|
|
598
|
+
[-0.425325, -0.688191, 0.587785],
|
|
599
|
+
[-0.16246, -0.262866, 0.951056],
|
|
600
|
+
[0.442863, -0.238856, 0.864188],
|
|
601
|
+
[0.16246, -0.262866, 0.951056],
|
|
602
|
+
[0.309017, -0.5, 0.809017],
|
|
603
|
+
[0.147621, -0.716567, 0.681718],
|
|
604
|
+
[0, -0.525731, 0.850651],
|
|
605
|
+
[0.425325, -0.688191, 0.587785],
|
|
606
|
+
[0.587785, -0.425325, 0.688191],
|
|
607
|
+
[0.688191, -0.587785, 0.425325],
|
|
608
|
+
[-0.955423, 0.295242, 0],
|
|
609
|
+
[-0.951056, 0.16246, 0.262866],
|
|
610
|
+
[-1, 0, 0],
|
|
611
|
+
[-0.850651, 0, 0.525731],
|
|
612
|
+
[-0.955423, -0.295242, 0],
|
|
613
|
+
[-0.951056, -0.16246, 0.262866],
|
|
614
|
+
[-0.864188, 0.442863, -0.238856],
|
|
615
|
+
[-0.951056, 0.16246, -0.262866],
|
|
616
|
+
[-0.809017, 0.309017, -0.5],
|
|
617
|
+
[-0.864188, -0.442863, -0.238856],
|
|
618
|
+
[-0.951056, -0.16246, -0.262866],
|
|
619
|
+
[-0.809017, -0.309017, -0.5],
|
|
620
|
+
[-0.681718, 0.147621, -0.716567],
|
|
621
|
+
[-0.681718, -0.147621, -0.716567],
|
|
622
|
+
[-0.850651, 0, -0.525731],
|
|
623
|
+
[-0.688191, 0.587785, -0.425325],
|
|
624
|
+
[-0.587785, 0.425325, -0.688191],
|
|
625
|
+
[-0.425325, 0.688191, -0.587785],
|
|
626
|
+
[-0.425325, -0.688191, -0.587785],
|
|
627
|
+
[-0.587785, -0.425325, -0.688191],
|
|
628
|
+
[-0.688191, -0.587785, -0.425325]
|
|
629
|
+
];
|
|
466
630
|
STATE_SIZE = 624;
|
|
467
631
|
MIDDLE_WORD = 397;
|
|
468
632
|
MATRIX_A = 2567483615;
|
|
@@ -1166,6 +1330,333 @@ var init_esm = __esm({
|
|
|
1166
1330
|
velocity: finalVelocity
|
|
1167
1331
|
};
|
|
1168
1332
|
};
|
|
1333
|
+
BinaryWriter = class {
|
|
1334
|
+
constructor(sizeOrBuffer = 1400) {
|
|
1335
|
+
if (typeof sizeOrBuffer === "number") {
|
|
1336
|
+
this.buffer = new Uint8Array(sizeOrBuffer);
|
|
1337
|
+
this.fixed = false;
|
|
1338
|
+
} else {
|
|
1339
|
+
this.buffer = sizeOrBuffer;
|
|
1340
|
+
this.fixed = true;
|
|
1341
|
+
}
|
|
1342
|
+
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
1343
|
+
this.offset = 0;
|
|
1344
|
+
}
|
|
1345
|
+
ensureSpace(bytes) {
|
|
1346
|
+
if (this.offset + bytes > this.buffer.byteLength) {
|
|
1347
|
+
if (this.fixed) {
|
|
1348
|
+
throw new Error(`Buffer overflow: capacity ${this.buffer.byteLength}, needed ${this.offset + bytes}`);
|
|
1349
|
+
}
|
|
1350
|
+
const newSize = Math.max(this.buffer.byteLength * 2, this.offset + bytes);
|
|
1351
|
+
const newBuffer = new Uint8Array(newSize);
|
|
1352
|
+
newBuffer.set(this.buffer);
|
|
1353
|
+
this.buffer = newBuffer;
|
|
1354
|
+
this.view = new DataView(this.buffer.buffer, this.buffer.byteOffset, this.buffer.byteLength);
|
|
1355
|
+
}
|
|
1356
|
+
}
|
|
1357
|
+
writeByte(value) {
|
|
1358
|
+
this.ensureSpace(1);
|
|
1359
|
+
this.view.setUint8(this.offset, value);
|
|
1360
|
+
this.offset += 1;
|
|
1361
|
+
}
|
|
1362
|
+
writeChar(value) {
|
|
1363
|
+
this.ensureSpace(1);
|
|
1364
|
+
this.view.setInt8(this.offset, value);
|
|
1365
|
+
this.offset += 1;
|
|
1366
|
+
}
|
|
1367
|
+
writeShort(value) {
|
|
1368
|
+
this.ensureSpace(2);
|
|
1369
|
+
this.view.setInt16(this.offset, value, true);
|
|
1370
|
+
this.offset += 2;
|
|
1371
|
+
}
|
|
1372
|
+
writeLong(value) {
|
|
1373
|
+
this.ensureSpace(4);
|
|
1374
|
+
this.view.setInt32(this.offset, value, true);
|
|
1375
|
+
this.offset += 4;
|
|
1376
|
+
}
|
|
1377
|
+
writeFloat(value) {
|
|
1378
|
+
this.ensureSpace(4);
|
|
1379
|
+
this.view.setFloat32(this.offset, value, true);
|
|
1380
|
+
this.offset += 4;
|
|
1381
|
+
}
|
|
1382
|
+
writeString(value) {
|
|
1383
|
+
const len = value.length;
|
|
1384
|
+
this.ensureSpace(len + 1);
|
|
1385
|
+
for (let i = 0; i < len; i++) {
|
|
1386
|
+
this.view.setUint8(this.offset + i, value.charCodeAt(i));
|
|
1387
|
+
}
|
|
1388
|
+
this.view.setUint8(this.offset + len, 0);
|
|
1389
|
+
this.offset += len + 1;
|
|
1390
|
+
}
|
|
1391
|
+
writeCoord(value) {
|
|
1392
|
+
this.writeShort(Math.trunc(value * 8));
|
|
1393
|
+
}
|
|
1394
|
+
writeAngle(value) {
|
|
1395
|
+
this.writeByte(Math.trunc(value * 256 / 360) & 255);
|
|
1396
|
+
}
|
|
1397
|
+
writeAngle16(value) {
|
|
1398
|
+
this.writeShort(Math.trunc(value * 65536 / 360) & 65535);
|
|
1399
|
+
}
|
|
1400
|
+
writePos(pos) {
|
|
1401
|
+
this.writeCoord(pos.x);
|
|
1402
|
+
this.writeCoord(pos.y);
|
|
1403
|
+
this.writeCoord(pos.z);
|
|
1404
|
+
}
|
|
1405
|
+
writeDir(dir) {
|
|
1406
|
+
let maxDot = -1;
|
|
1407
|
+
let bestIndex = 0;
|
|
1408
|
+
if (dir.x === 0 && dir.y === 0 && dir.z === 0) {
|
|
1409
|
+
this.writeByte(0);
|
|
1410
|
+
return;
|
|
1411
|
+
}
|
|
1412
|
+
for (let i = 0; i < ANORMS.length; i++) {
|
|
1413
|
+
const norm = ANORMS[i];
|
|
1414
|
+
const dot = dir.x * norm[0] + dir.y * norm[1] + dir.z * norm[2];
|
|
1415
|
+
if (dot > maxDot) {
|
|
1416
|
+
maxDot = dot;
|
|
1417
|
+
bestIndex = i;
|
|
1418
|
+
}
|
|
1419
|
+
}
|
|
1420
|
+
this.writeByte(bestIndex);
|
|
1421
|
+
}
|
|
1422
|
+
getData() {
|
|
1423
|
+
return this.buffer.slice(0, this.offset);
|
|
1424
|
+
}
|
|
1425
|
+
getBuffer() {
|
|
1426
|
+
return this.buffer;
|
|
1427
|
+
}
|
|
1428
|
+
getOffset() {
|
|
1429
|
+
return this.offset;
|
|
1430
|
+
}
|
|
1431
|
+
reset() {
|
|
1432
|
+
this.offset = 0;
|
|
1433
|
+
}
|
|
1434
|
+
};
|
|
1435
|
+
_NetChan = class _NetChan2 {
|
|
1436
|
+
constructor() {
|
|
1437
|
+
this.qport = 0;
|
|
1438
|
+
this.incomingSequence = 0;
|
|
1439
|
+
this.outgoingSequence = 0;
|
|
1440
|
+
this.incomingAcknowledged = 0;
|
|
1441
|
+
this.incomingReliableAcknowledged = false;
|
|
1442
|
+
this.incomingReliableSequence = 0;
|
|
1443
|
+
this.outgoingReliableSequence = 0;
|
|
1444
|
+
this.reliableLength = 0;
|
|
1445
|
+
this.lastReceived = 0;
|
|
1446
|
+
this.lastSent = 0;
|
|
1447
|
+
this.remoteAddress = null;
|
|
1448
|
+
this.reliableMessage = new BinaryWriter(_NetChan2.MAX_MSGLEN);
|
|
1449
|
+
const now = Date.now();
|
|
1450
|
+
this.lastReceived = now;
|
|
1451
|
+
this.lastSent = now;
|
|
1452
|
+
this.qport = Math.floor(Math.random() * 65536);
|
|
1453
|
+
}
|
|
1454
|
+
/**
|
|
1455
|
+
* Setup the netchan with specific settings
|
|
1456
|
+
*/
|
|
1457
|
+
setup(qport, address = null) {
|
|
1458
|
+
this.qport = qport;
|
|
1459
|
+
this.remoteAddress = address;
|
|
1460
|
+
this.reset();
|
|
1461
|
+
}
|
|
1462
|
+
/**
|
|
1463
|
+
* Reset the netchan state
|
|
1464
|
+
*/
|
|
1465
|
+
reset() {
|
|
1466
|
+
this.incomingSequence = 0;
|
|
1467
|
+
this.outgoingSequence = 0;
|
|
1468
|
+
this.incomingAcknowledged = 0;
|
|
1469
|
+
this.incomingReliableAcknowledged = false;
|
|
1470
|
+
this.incomingReliableSequence = 0;
|
|
1471
|
+
this.outgoingReliableSequence = 0;
|
|
1472
|
+
this.reliableLength = 0;
|
|
1473
|
+
this.reliableMessage.reset();
|
|
1474
|
+
this.lastReceived = Date.now();
|
|
1475
|
+
this.lastSent = Date.now();
|
|
1476
|
+
}
|
|
1477
|
+
/**
|
|
1478
|
+
* Transmits a packet containing reliable and unreliable data
|
|
1479
|
+
*/
|
|
1480
|
+
transmit(unreliableData) {
|
|
1481
|
+
this.outgoingSequence++;
|
|
1482
|
+
this.lastSent = Date.now();
|
|
1483
|
+
const headerSize = _NetChan2.PACKET_HEADER;
|
|
1484
|
+
const reliableSize = this.reliableLength > 0 ? this.reliableLength + 2 : 0;
|
|
1485
|
+
let unreliableSize = unreliableData ? unreliableData.length : 0;
|
|
1486
|
+
if (headerSize + reliableSize + unreliableSize > _NetChan2.MAX_MSGLEN) {
|
|
1487
|
+
unreliableSize = _NetChan2.MAX_MSGLEN - headerSize - reliableSize;
|
|
1488
|
+
if (unreliableSize < 0) unreliableSize = 0;
|
|
1489
|
+
}
|
|
1490
|
+
const buffer = new ArrayBuffer(headerSize + reliableSize + unreliableSize);
|
|
1491
|
+
const view = new DataView(buffer);
|
|
1492
|
+
const result = new Uint8Array(buffer);
|
|
1493
|
+
let sequence = this.outgoingSequence;
|
|
1494
|
+
if (this.reliableLength > 0) {
|
|
1495
|
+
sequence |= 2147483648;
|
|
1496
|
+
if ((this.outgoingReliableSequence & 1) !== 0) {
|
|
1497
|
+
sequence |= 1073741824;
|
|
1498
|
+
}
|
|
1499
|
+
}
|
|
1500
|
+
view.setUint32(0, sequence, true);
|
|
1501
|
+
let ack = this.incomingSequence;
|
|
1502
|
+
if ((this.incomingReliableSequence & 1) !== 0) {
|
|
1503
|
+
ack |= 2147483648;
|
|
1504
|
+
}
|
|
1505
|
+
view.setUint32(4, ack, true);
|
|
1506
|
+
view.setUint16(8, this.qport, true);
|
|
1507
|
+
let offset = headerSize;
|
|
1508
|
+
if (this.reliableLength > 0) {
|
|
1509
|
+
view.setUint16(offset, this.reliableLength, true);
|
|
1510
|
+
offset += 2;
|
|
1511
|
+
const reliableBuffer = this.reliableMessage.getBuffer();
|
|
1512
|
+
const reliableBytes = reliableBuffer.subarray(0, this.reliableLength);
|
|
1513
|
+
result.set(reliableBytes, offset);
|
|
1514
|
+
offset += this.reliableLength;
|
|
1515
|
+
}
|
|
1516
|
+
if (unreliableData && unreliableSize > 0) {
|
|
1517
|
+
const chunk = unreliableData.slice(0, unreliableSize);
|
|
1518
|
+
result.set(chunk, offset);
|
|
1519
|
+
}
|
|
1520
|
+
return result;
|
|
1521
|
+
}
|
|
1522
|
+
/**
|
|
1523
|
+
* Processes a received packet
|
|
1524
|
+
* Returns the payload data (reliable + unreliable) to be processed, or null if discarded
|
|
1525
|
+
*/
|
|
1526
|
+
process(packet) {
|
|
1527
|
+
if (packet.length < _NetChan2.PACKET_HEADER) {
|
|
1528
|
+
return null;
|
|
1529
|
+
}
|
|
1530
|
+
this.lastReceived = Date.now();
|
|
1531
|
+
const view = new DataView(packet.buffer, packet.byteOffset, packet.byteLength);
|
|
1532
|
+
const sequence = view.getUint32(0, true);
|
|
1533
|
+
const ack = view.getUint32(4, true);
|
|
1534
|
+
const qport = view.getUint16(8, true);
|
|
1535
|
+
if (this.qport !== qport) {
|
|
1536
|
+
return null;
|
|
1537
|
+
}
|
|
1538
|
+
const seqNumberClean = sequence & ~(2147483648 | 1073741824);
|
|
1539
|
+
if ((seqNumberClean - this.incomingSequence | 0) <= 0) {
|
|
1540
|
+
return null;
|
|
1541
|
+
}
|
|
1542
|
+
this.incomingSequence = seqNumberClean;
|
|
1543
|
+
const ackNumber = ack & ~2147483648;
|
|
1544
|
+
const ackReliable = (ack & 2147483648) !== 0;
|
|
1545
|
+
if (ackNumber > this.incomingAcknowledged) {
|
|
1546
|
+
this.incomingAcknowledged = ackNumber;
|
|
1547
|
+
}
|
|
1548
|
+
if (this.reliableLength > 0) {
|
|
1549
|
+
const receivedAckBit = ackReliable ? 1 : 0;
|
|
1550
|
+
const currentReliableBit = this.outgoingReliableSequence & 1;
|
|
1551
|
+
if (receivedAckBit !== currentReliableBit) {
|
|
1552
|
+
this.reliableLength = 0;
|
|
1553
|
+
this.reliableMessage.reset();
|
|
1554
|
+
this.outgoingReliableSequence ^= 1;
|
|
1555
|
+
}
|
|
1556
|
+
}
|
|
1557
|
+
const hasReliableData = (sequence & 2147483648) !== 0;
|
|
1558
|
+
const reliableSeqBit = (sequence & 1073741824) !== 0 ? 1 : 0;
|
|
1559
|
+
let payloadOffset = _NetChan2.PACKET_HEADER;
|
|
1560
|
+
let reliableData = null;
|
|
1561
|
+
if (hasReliableData) {
|
|
1562
|
+
if (payloadOffset + 2 > packet.byteLength) return null;
|
|
1563
|
+
const reliableLen = view.getUint16(payloadOffset, true);
|
|
1564
|
+
payloadOffset += 2;
|
|
1565
|
+
const expectedBit = this.incomingReliableSequence & 1;
|
|
1566
|
+
if (reliableSeqBit === expectedBit) {
|
|
1567
|
+
this.incomingReliableSequence++;
|
|
1568
|
+
if (payloadOffset + reliableLen > packet.byteLength) return null;
|
|
1569
|
+
reliableData = packet.slice(payloadOffset, payloadOffset + reliableLen);
|
|
1570
|
+
}
|
|
1571
|
+
payloadOffset += reliableLen;
|
|
1572
|
+
}
|
|
1573
|
+
const unreliableData = packet.slice(payloadOffset);
|
|
1574
|
+
if (reliableData && reliableData.length > 0) {
|
|
1575
|
+
const totalLen = reliableData.length + unreliableData.length;
|
|
1576
|
+
const result = new Uint8Array(totalLen);
|
|
1577
|
+
result.set(reliableData, 0);
|
|
1578
|
+
result.set(unreliableData, reliableData.length);
|
|
1579
|
+
return result;
|
|
1580
|
+
}
|
|
1581
|
+
if (unreliableData) {
|
|
1582
|
+
return unreliableData;
|
|
1583
|
+
}
|
|
1584
|
+
return new Uint8Array(0);
|
|
1585
|
+
}
|
|
1586
|
+
/**
|
|
1587
|
+
* Checks if reliable message buffer is empty and ready for new data
|
|
1588
|
+
*/
|
|
1589
|
+
canSendReliable() {
|
|
1590
|
+
return this.reliableLength === 0;
|
|
1591
|
+
}
|
|
1592
|
+
/**
|
|
1593
|
+
* Writes a byte to the reliable message buffer
|
|
1594
|
+
*/
|
|
1595
|
+
writeReliableByte(value) {
|
|
1596
|
+
if (this.reliableLength + 1 > _NetChan2.MAX_MSGLEN - _NetChan2.HEADER_OVERHEAD) {
|
|
1597
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
1598
|
+
}
|
|
1599
|
+
this.reliableMessage.writeByte(value);
|
|
1600
|
+
this.reliableLength++;
|
|
1601
|
+
}
|
|
1602
|
+
/**
|
|
1603
|
+
* Writes a short to the reliable message buffer
|
|
1604
|
+
*/
|
|
1605
|
+
writeReliableShort(value) {
|
|
1606
|
+
if (this.reliableLength + 2 > _NetChan2.MAX_MSGLEN - _NetChan2.HEADER_OVERHEAD) {
|
|
1607
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
1608
|
+
}
|
|
1609
|
+
this.reliableMessage.writeShort(value);
|
|
1610
|
+
this.reliableLength += 2;
|
|
1611
|
+
}
|
|
1612
|
+
/**
|
|
1613
|
+
* Writes a long to the reliable message buffer
|
|
1614
|
+
*/
|
|
1615
|
+
writeReliableLong(value) {
|
|
1616
|
+
if (this.reliableLength + 4 > _NetChan2.MAX_MSGLEN - _NetChan2.HEADER_OVERHEAD) {
|
|
1617
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
1618
|
+
}
|
|
1619
|
+
this.reliableMessage.writeLong(value);
|
|
1620
|
+
this.reliableLength += 4;
|
|
1621
|
+
}
|
|
1622
|
+
/**
|
|
1623
|
+
* Writes a string to the reliable message buffer
|
|
1624
|
+
*/
|
|
1625
|
+
writeReliableString(value) {
|
|
1626
|
+
const len = value.length + 1;
|
|
1627
|
+
if (this.reliableLength + len > _NetChan2.MAX_MSGLEN - _NetChan2.HEADER_OVERHEAD) {
|
|
1628
|
+
throw new Error("NetChan reliable buffer overflow");
|
|
1629
|
+
}
|
|
1630
|
+
this.reliableMessage.writeString(value);
|
|
1631
|
+
this.reliableLength += len;
|
|
1632
|
+
}
|
|
1633
|
+
/**
|
|
1634
|
+
* Returns the current reliable data buffer
|
|
1635
|
+
*/
|
|
1636
|
+
getReliableData() {
|
|
1637
|
+
if (this.reliableLength === 0) {
|
|
1638
|
+
return new Uint8Array(0);
|
|
1639
|
+
}
|
|
1640
|
+
const buffer = this.reliableMessage.getBuffer();
|
|
1641
|
+
return buffer.subarray(0, this.reliableLength);
|
|
1642
|
+
}
|
|
1643
|
+
/**
|
|
1644
|
+
* Checks if we need to send a keepalive packet
|
|
1645
|
+
*/
|
|
1646
|
+
needsKeepalive(currentTime) {
|
|
1647
|
+
return currentTime - this.lastSent > 1e3;
|
|
1648
|
+
}
|
|
1649
|
+
/**
|
|
1650
|
+
* Checks if the connection has timed out
|
|
1651
|
+
*/
|
|
1652
|
+
isTimedOut(currentTime, timeoutMs = 3e4) {
|
|
1653
|
+
return currentTime - this.lastReceived > timeoutMs;
|
|
1654
|
+
}
|
|
1655
|
+
};
|
|
1656
|
+
_NetChan.MAX_MSGLEN = 1400;
|
|
1657
|
+
_NetChan.FRAGMENT_SIZE = 1024;
|
|
1658
|
+
_NetChan.PACKET_HEADER = 10;
|
|
1659
|
+
_NetChan.HEADER_OVERHEAD = _NetChan.PACKET_HEADER + 2;
|
|
1169
1660
|
WeaponId = /* @__PURE__ */ ((WeaponId22) => {
|
|
1170
1661
|
WeaponId22["Blaster"] = "blaster";
|
|
1171
1662
|
WeaponId22["Shotgun"] = "shotgun";
|