@quake2ts/engine 0.0.753 → 0.0.756

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.
@@ -12011,46 +12011,7 @@ _StreamingBuffer.INITIAL_SIZE = 64 * 1024;
12011
12011
  _StreamingBuffer.MAX_STRING_LENGTH = 2048;
12012
12012
  var StreamingBuffer = _StreamingBuffer;
12013
12013
 
12014
- // src/demo/parser.ts
12015
- var PROTOCOL_VERSION_RERELEASE = 2023;
12016
- var U_ORIGIN1 = 1 << 0;
12017
- var U_ORIGIN2 = 1 << 1;
12018
- var U_ANGLE2 = 1 << 2;
12019
- var U_ANGLE3 = 1 << 3;
12020
- var U_FRAME8 = 1 << 4;
12021
- var U_EVENT = 1 << 5;
12022
- var U_REMOVE = 1 << 6;
12023
- var U_MOREBITS1 = 1 << 7;
12024
- var U_NUMBER16 = 1 << 8;
12025
- var U_ORIGIN3 = 1 << 9;
12026
- var U_ANGLE1 = 1 << 10;
12027
- var U_MODEL = 1 << 11;
12028
- var U_RENDERFX8 = 1 << 12;
12029
- var U_ALPHA = 1 << 13;
12030
- var U_EFFECTS8 = 1 << 14;
12031
- var U_MOREBITS2 = 1 << 15;
12032
- var U_SKIN8 = 1 << 16;
12033
- var U_FRAME16 = 1 << 17;
12034
- var U_RENDERFX16 = 1 << 18;
12035
- var U_EFFECTS16 = 1 << 19;
12036
- var U_MODEL2 = 1 << 20;
12037
- var U_MODEL3 = 1 << 21;
12038
- var U_MODEL4 = 1 << 22;
12039
- var U_MOREBITS3 = 1 << 23;
12040
- var U_OLDORIGIN = 1 << 24;
12041
- var U_SKIN16 = 1 << 25;
12042
- var U_SOUND = 1 << 26;
12043
- var U_SOLID = 1 << 27;
12044
- var U_SCALE = 1 << 28;
12045
- var U_INSTANCE_BITS = 1 << 29;
12046
- var U_LOOP_VOLUME = 1 << 30;
12047
- var U_MOREBITS4 = 2147483648 | 0;
12048
- var U_LOOP_ATTENUATION_HIGH = 1 << 0;
12049
- var U_OWNER_HIGH = 1 << 1;
12050
- var U_OLD_FRAME_HIGH = 1 << 2;
12051
- var RECORD_CLIENT = 1;
12052
- var RECORD_SERVER = 2;
12053
- var RECORD_RELAY = 128;
12014
+ // src/demo/state.ts
12054
12015
  var createEmptyEntityState = () => ({
12055
12016
  number: 0,
12056
12017
  modelindex: 0,
@@ -12102,6 +12063,575 @@ var createEmptyProtocolPlayerState = () => ({
12102
12063
  team_id: 0,
12103
12064
  watertype: 0
12104
12065
  });
12066
+
12067
+ // src/demo/protocol/quake2.ts
12068
+ var PROTO34_MAP = {
12069
+ 0: shared.ServerCommand.bad,
12070
+ 1: shared.ServerCommand.nop,
12071
+ 2: shared.ServerCommand.disconnect,
12072
+ 3: shared.ServerCommand.reconnect,
12073
+ 4: shared.ServerCommand.download,
12074
+ 5: shared.ServerCommand.frame,
12075
+ 6: shared.ServerCommand.inventory,
12076
+ 7: shared.ServerCommand.layout,
12077
+ 8: shared.ServerCommand.muzzleflash,
12078
+ 9: shared.ServerCommand.temp_entity,
12079
+ 10: shared.ServerCommand.sound,
12080
+ 11: shared.ServerCommand.print,
12081
+ 12: shared.ServerCommand.stufftext,
12082
+ 13: shared.ServerCommand.serverdata,
12083
+ 14: shared.ServerCommand.configstring,
12084
+ 15: shared.ServerCommand.spawnbaseline,
12085
+ 16: shared.ServerCommand.centerprint,
12086
+ 17: shared.ServerCommand.playerinfo,
12087
+ 18: shared.ServerCommand.packetentities,
12088
+ 19: shared.ServerCommand.deltapacketentities,
12089
+ 20: shared.ServerCommand.muzzleflash2
12090
+ };
12091
+ var Quake2ProtocolHandler = class {
12092
+ constructor() {
12093
+ this.protocolVersion = 34;
12094
+ }
12095
+ translateCommand(cmd) {
12096
+ if (PROTO34_MAP[cmd] !== void 0) {
12097
+ return PROTO34_MAP[cmd];
12098
+ }
12099
+ return shared.ServerCommand.bad;
12100
+ }
12101
+ parseServerData(stream) {
12102
+ const protocol = stream.readLong();
12103
+ const serverCount = stream.readLong();
12104
+ const attractLoop = stream.readByte();
12105
+ const gameDir = stream.readString();
12106
+ const playerNum = stream.readShort();
12107
+ const levelName = stream.readString();
12108
+ return {
12109
+ protocol,
12110
+ serverCount,
12111
+ attractLoop,
12112
+ gameDir,
12113
+ playerNum,
12114
+ levelName
12115
+ };
12116
+ }
12117
+ parseEntityBits(stream) {
12118
+ let total = stream.readByte();
12119
+ if (total & shared.U_MOREBITS1) total |= stream.readByte() << 8;
12120
+ if (total & shared.U_MOREBITS2) total |= stream.readByte() << 16;
12121
+ if (total & shared.U_MOREBITS3) total |= stream.readByte() << 24;
12122
+ let number;
12123
+ if (total & shared.U_NUMBER16) number = stream.readShort();
12124
+ else number = stream.readByte();
12125
+ return { number, bits: total, bitsHigh: 0 };
12126
+ }
12127
+ parseDelta(from, to, number, bits, bitsHigh, stream) {
12128
+ to.number = from.number;
12129
+ to.modelindex = from.modelindex;
12130
+ to.modelindex2 = from.modelindex2;
12131
+ to.modelindex3 = from.modelindex3;
12132
+ to.modelindex4 = from.modelindex4;
12133
+ to.frame = from.frame;
12134
+ to.skinnum = from.skinnum;
12135
+ to.effects = from.effects;
12136
+ to.renderfx = from.renderfx;
12137
+ to.origin.x = from.origin.x;
12138
+ to.origin.y = from.origin.y;
12139
+ to.origin.z = from.origin.z;
12140
+ to.old_origin.x = from.origin.x;
12141
+ to.old_origin.y = from.origin.y;
12142
+ to.old_origin.z = from.origin.z;
12143
+ to.angles.x = from.angles.x;
12144
+ to.angles.y = from.angles.y;
12145
+ to.angles.z = from.angles.z;
12146
+ to.sound = from.sound;
12147
+ to.event = from.event;
12148
+ to.solid = from.solid;
12149
+ to.number = number;
12150
+ to.bits = bits;
12151
+ if (bits & shared.U_MODEL) to.modelindex = stream.readByte();
12152
+ if (bits & shared.U_MODEL2) to.modelindex2 = stream.readByte();
12153
+ if (bits & shared.U_MODEL3) to.modelindex3 = stream.readByte();
12154
+ if (bits & shared.U_MODEL4) to.modelindex4 = stream.readByte();
12155
+ if (bits & shared.U_FRAME8) to.frame = stream.readByte();
12156
+ if (bits & shared.U_FRAME16) to.frame = stream.readShort();
12157
+ if (bits & shared.U_SKIN8 && bits & shared.U_SKIN16) to.skinnum = stream.readLong();
12158
+ else if (bits & shared.U_SKIN8) to.skinnum = stream.readByte();
12159
+ else if (bits & shared.U_SKIN16) to.skinnum = stream.readShort();
12160
+ if (bits & shared.U_EFFECTS8 && bits & shared.U_EFFECTS16) to.effects = stream.readLong();
12161
+ else if (bits & shared.U_EFFECTS8) to.effects = stream.readByte();
12162
+ else if (bits & shared.U_EFFECTS16) to.effects = stream.readShort();
12163
+ if (bits & shared.U_RENDERFX8 && bits & shared.U_RENDERFX16) to.renderfx = stream.readLong();
12164
+ else if (bits & shared.U_RENDERFX8) to.renderfx = stream.readByte();
12165
+ else if (bits & shared.U_RENDERFX16) to.renderfx = stream.readShort();
12166
+ if (bits & shared.U_ORIGIN1) to.origin.x = stream.readShort() * 0.125;
12167
+ if (bits & shared.U_ORIGIN2) to.origin.y = stream.readShort() * 0.125;
12168
+ if (bits & shared.U_ORIGIN3) to.origin.z = stream.readShort() * 0.125;
12169
+ if (bits & shared.U_ANGLE1) to.angles.x = stream.readByte() * (360 / 256);
12170
+ if (bits & shared.U_ANGLE2) to.angles.y = stream.readByte() * (360 / 256);
12171
+ if (bits & shared.U_ANGLE3) to.angles.z = stream.readByte() * (360 / 256);
12172
+ if (bits & shared.U_OLDORIGIN) {
12173
+ to.old_origin.x = stream.readShort() * 0.125;
12174
+ to.old_origin.y = stream.readShort() * 0.125;
12175
+ to.old_origin.z = stream.readShort() * 0.125;
12176
+ }
12177
+ if (bits & shared.U_SOUND) to.sound = stream.readByte();
12178
+ if (bits & shared.U_EVENT) to.event = stream.readByte();
12179
+ else to.event = 0;
12180
+ if (bits & shared.U_SOLID) to.solid = stream.readShort();
12181
+ }
12182
+ parsePlayerState(stream) {
12183
+ const ps = createEmptyProtocolPlayerState();
12184
+ const flags = stream.readShort();
12185
+ if (flags & 1) ps.pm_type = stream.readByte();
12186
+ if (flags & 2) {
12187
+ ps.origin.x = stream.readShort() * 0.125;
12188
+ ps.origin.y = stream.readShort() * 0.125;
12189
+ ps.origin.z = stream.readShort() * 0.125;
12190
+ }
12191
+ if (flags & 4) {
12192
+ ps.velocity.x = stream.readShort() * 0.125;
12193
+ ps.velocity.y = stream.readShort() * 0.125;
12194
+ ps.velocity.z = stream.readShort() * 0.125;
12195
+ }
12196
+ if (flags & 8) ps.pm_time = stream.readByte();
12197
+ if (flags & 16) ps.pm_flags = stream.readByte();
12198
+ if (flags & 32) ps.gravity = stream.readShort();
12199
+ if (flags & 64) {
12200
+ ps.delta_angles.x = stream.readShort() * (180 / 32768);
12201
+ ps.delta_angles.y = stream.readShort() * (180 / 32768);
12202
+ ps.delta_angles.z = stream.readShort() * (180 / 32768);
12203
+ }
12204
+ if (flags & 128) {
12205
+ ps.viewoffset.x = (stream.readByte() << 24 >> 24) * 0.25;
12206
+ ps.viewoffset.y = (stream.readByte() << 24 >> 24) * 0.25;
12207
+ ps.viewoffset.z = (stream.readByte() << 24 >> 24) * 0.25;
12208
+ }
12209
+ if (flags & 256) {
12210
+ ps.viewangles.x = stream.readShort() * (360 / 65536);
12211
+ ps.viewangles.y = stream.readShort() * (360 / 65536);
12212
+ ps.viewangles.z = stream.readShort() * (360 / 65536);
12213
+ }
12214
+ if (flags & 512) {
12215
+ ps.kick_angles.x = (stream.readByte() << 24 >> 24) * 0.25;
12216
+ ps.kick_angles.y = (stream.readByte() << 24 >> 24) * 0.25;
12217
+ ps.kick_angles.z = (stream.readByte() << 24 >> 24) * 0.25;
12218
+ }
12219
+ if (flags & 4096) ps.gun_index = stream.readByte();
12220
+ if (flags & 8192) {
12221
+ ps.gun_frame = stream.readByte();
12222
+ ps.gun_offset.x = (stream.readByte() << 24 >> 24) * 0.25;
12223
+ ps.gun_offset.y = (stream.readByte() << 24 >> 24) * 0.25;
12224
+ ps.gun_offset.z = (stream.readByte() << 24 >> 24) * 0.25;
12225
+ ps.gun_angles.x = (stream.readByte() << 24 >> 24) * 0.25;
12226
+ ps.gun_angles.y = (stream.readByte() << 24 >> 24) * 0.25;
12227
+ ps.gun_angles.z = (stream.readByte() << 24 >> 24) * 0.25;
12228
+ }
12229
+ if (flags & 1024) {
12230
+ ps.blend[0] = stream.readByte();
12231
+ ps.blend[1] = stream.readByte();
12232
+ ps.blend[2] = stream.readByte();
12233
+ ps.blend[3] = stream.readByte();
12234
+ }
12235
+ if (flags & 2048) ps.fov = stream.readByte();
12236
+ if (flags & 16384) ps.rdflags = stream.readByte();
12237
+ if (flags & 32768) ps.watertype = stream.readByte();
12238
+ const statbits = stream.readLong();
12239
+ for (let i = 0; i < 32; i++) {
12240
+ if (statbits & 1 << i) ps.stats[i] = stream.readShort();
12241
+ }
12242
+ return ps;
12243
+ }
12244
+ };
12245
+ var PROTOCOL_VERSION_RERELEASE = 2023;
12246
+ var RereleaseProtocolHandler = class {
12247
+ constructor() {
12248
+ this.protocolVersion = PROTOCOL_VERSION_RERELEASE;
12249
+ }
12250
+ translateCommand(cmd) {
12251
+ return cmd;
12252
+ }
12253
+ parseServerData(stream) {
12254
+ const protocol = stream.readLong();
12255
+ const spawnCount = stream.readLong();
12256
+ const demoType = stream.readByte();
12257
+ const tickRate = stream.readByte();
12258
+ const gameDir = stream.readString();
12259
+ let playerNum = stream.readShort();
12260
+ if (playerNum === -2) {
12261
+ const numSplits = stream.readShort();
12262
+ for (let i = 0; i < numSplits; i++) stream.readShort();
12263
+ playerNum = 0;
12264
+ } else if (playerNum === -1) {
12265
+ playerNum = -1;
12266
+ }
12267
+ const levelName = stream.readString();
12268
+ return {
12269
+ protocol,
12270
+ serverCount: spawnCount,
12271
+ // Map spawnCount to serverCount interface
12272
+ spawnCount,
12273
+ attractLoop: 0,
12274
+ // Not used in rerelease
12275
+ gameDir,
12276
+ playerNum,
12277
+ levelName,
12278
+ tickRate,
12279
+ demoType
12280
+ };
12281
+ }
12282
+ parseEntityBits(stream) {
12283
+ let total = stream.readByte();
12284
+ if (total & shared.U_MOREBITS1) total |= stream.readByte() << 8;
12285
+ if (total & shared.U_MOREBITS2) total |= stream.readByte() << 16;
12286
+ if (total & shared.U_MOREBITS3) total |= stream.readByte() << 24;
12287
+ let bitsHigh = 0;
12288
+ if (total & shared.U_MOREBITS4) bitsHigh = stream.readByte();
12289
+ let number;
12290
+ if (total & shared.U_NUMBER16) number = stream.readShort();
12291
+ else number = stream.readByte();
12292
+ return { number, bits: total, bitsHigh };
12293
+ }
12294
+ parseDelta(from, to, number, bits, bitsHigh, stream) {
12295
+ Object.assign(to, from);
12296
+ to.origin = { ...from.origin };
12297
+ to.old_origin = { ...from.old_origin };
12298
+ to.angles = { ...from.angles };
12299
+ to.number = number;
12300
+ to.bits = bits;
12301
+ to.bitsHigh = bitsHigh;
12302
+ if (bits & shared.U_MODEL) to.modelindex = stream.readByte();
12303
+ if (bits & shared.U_MODEL2) to.modelindex2 = stream.readByte();
12304
+ if (bits & shared.U_MODEL3) to.modelindex3 = stream.readByte();
12305
+ if (bits & shared.U_MODEL4) to.modelindex4 = stream.readByte();
12306
+ if (bits & shared.U_FRAME8) to.frame = stream.readByte();
12307
+ if (bits & shared.U_FRAME16) to.frame = stream.readShort();
12308
+ if (bits & shared.U_SKIN8 && bits & shared.U_SKIN16) to.skinnum = stream.readLong();
12309
+ else if (bits & shared.U_SKIN8) to.skinnum = stream.readByte();
12310
+ else if (bits & shared.U_SKIN16) to.skinnum = stream.readShort();
12311
+ if (bits & shared.U_EFFECTS8 && bits & shared.U_EFFECTS16) to.effects = stream.readLong();
12312
+ else if (bits & shared.U_EFFECTS8) to.effects = stream.readByte();
12313
+ else if (bits & shared.U_EFFECTS16) to.effects = stream.readShort();
12314
+ if (bits & shared.U_RENDERFX8 && bits & shared.U_RENDERFX16) to.renderfx = stream.readLong();
12315
+ else if (bits & shared.U_RENDERFX8) to.renderfx = stream.readByte();
12316
+ else if (bits & shared.U_RENDERFX16) to.renderfx = stream.readShort();
12317
+ if (bits & shared.U_ORIGIN1) to.origin.x = stream.readShort() * 0.125;
12318
+ if (bits & shared.U_ORIGIN2) to.origin.y = stream.readShort() * 0.125;
12319
+ if (bits & shared.U_ORIGIN3) to.origin.z = stream.readShort() * 0.125;
12320
+ if (bits & shared.U_ANGLE1) to.angles.x = stream.readByte() * (360 / 256);
12321
+ if (bits & shared.U_ANGLE2) to.angles.y = stream.readByte() * (360 / 256);
12322
+ if (bits & shared.U_ANGLE3) to.angles.z = stream.readByte() * (360 / 256);
12323
+ if (bits & shared.U_OLDORIGIN) {
12324
+ to.old_origin.x = stream.readShort() * 0.125;
12325
+ to.old_origin.y = stream.readShort() * 0.125;
12326
+ to.old_origin.z = stream.readShort() * 0.125;
12327
+ }
12328
+ if (bits & shared.U_SOUND) to.sound = stream.readByte();
12329
+ if (bits & shared.U_EVENT) to.event = stream.readByte();
12330
+ else to.event = 0;
12331
+ if (bits & shared.U_SOLID) to.solid = stream.readShort();
12332
+ if (bits & shared.U_ALPHA) to.alpha = stream.readByte() / 255;
12333
+ if (bits & shared.U_SCALE) to.scale = stream.readFloat();
12334
+ if (bits & shared.U_INSTANCE_BITS) to.instanceBits = stream.readLong();
12335
+ if (bits & shared.U_LOOP_VOLUME) to.loopVolume = stream.readByte() / 255;
12336
+ if (bitsHigh & shared.U_LOOP_ATTENUATION_HIGH) to.loopAttenuation = stream.readByte() / 255;
12337
+ if (bitsHigh & shared.U_OWNER_HIGH) to.owner = stream.readShort();
12338
+ if (bitsHigh & shared.U_OLD_FRAME_HIGH) to.oldFrame = stream.readShort();
12339
+ }
12340
+ parsePlayerState(stream) {
12341
+ const ps = createEmptyProtocolPlayerState();
12342
+ const flags = stream.readShort();
12343
+ if (flags & 1) ps.pm_type = stream.readByte();
12344
+ if (flags & 2) {
12345
+ ps.origin.x = stream.readShort() * 0.125;
12346
+ ps.origin.y = stream.readShort() * 0.125;
12347
+ ps.origin.z = stream.readShort() * 0.125;
12348
+ }
12349
+ if (flags & 4) {
12350
+ ps.velocity.x = stream.readShort() * 0.125;
12351
+ ps.velocity.y = stream.readShort() * 0.125;
12352
+ ps.velocity.z = stream.readShort() * 0.125;
12353
+ }
12354
+ if (flags & 8) ps.pm_time = stream.readByte();
12355
+ if (flags & 16) ps.pm_flags = stream.readByte();
12356
+ if (flags & 32) ps.gravity = stream.readShort();
12357
+ if (flags & 64) {
12358
+ ps.delta_angles.x = stream.readShort() * (180 / 32768);
12359
+ ps.delta_angles.y = stream.readShort() * (180 / 32768);
12360
+ ps.delta_angles.z = stream.readShort() * (180 / 32768);
12361
+ }
12362
+ if (flags & 128) {
12363
+ ps.viewoffset.x = (stream.readByte() << 24 >> 24) * 0.25;
12364
+ ps.viewoffset.y = (stream.readByte() << 24 >> 24) * 0.25;
12365
+ ps.viewoffset.z = (stream.readByte() << 24 >> 24) * 0.25;
12366
+ }
12367
+ if (flags & 256) {
12368
+ ps.viewangles.x = stream.readShort() * (360 / 65536);
12369
+ ps.viewangles.y = stream.readShort() * (360 / 65536);
12370
+ ps.viewangles.z = stream.readShort() * (360 / 65536);
12371
+ }
12372
+ if (flags & 512) {
12373
+ ps.kick_angles.x = (stream.readByte() << 24 >> 24) * 0.25;
12374
+ ps.kick_angles.y = (stream.readByte() << 24 >> 24) * 0.25;
12375
+ ps.kick_angles.z = (stream.readByte() << 24 >> 24) * 0.25;
12376
+ }
12377
+ if (flags & 4096) ps.gun_index = stream.readByte();
12378
+ if (flags & 8192) {
12379
+ ps.gun_frame = stream.readByte();
12380
+ ps.gun_offset.x = (stream.readByte() << 24 >> 24) * 0.25;
12381
+ ps.gun_offset.y = (stream.readByte() << 24 >> 24) * 0.25;
12382
+ ps.gun_offset.z = (stream.readByte() << 24 >> 24) * 0.25;
12383
+ ps.gun_angles.x = (stream.readByte() << 24 >> 24) * 0.25;
12384
+ ps.gun_angles.y = (stream.readByte() << 24 >> 24) * 0.25;
12385
+ ps.gun_angles.z = (stream.readByte() << 24 >> 24) * 0.25;
12386
+ }
12387
+ if (flags & 1024) {
12388
+ ps.blend[0] = stream.readByte();
12389
+ ps.blend[1] = stream.readByte();
12390
+ ps.blend[2] = stream.readByte();
12391
+ ps.blend[3] = stream.readByte();
12392
+ }
12393
+ if (flags & 2048) ps.fov = stream.readByte();
12394
+ if (flags & 16384) ps.rdflags = stream.readByte();
12395
+ if (flags & 32768) ps.watertype = stream.readByte();
12396
+ const statbits = stream.readLong();
12397
+ for (let i = 0; i < 32; i++) {
12398
+ if (statbits & 1 << i) ps.stats[i] = stream.readShort();
12399
+ }
12400
+ return ps;
12401
+ }
12402
+ };
12403
+ var LegacyProtocolHandler = class {
12404
+ constructor(version = 0) {
12405
+ this.protocolVersion = version;
12406
+ }
12407
+ translateCommand(cmd) {
12408
+ return cmd;
12409
+ }
12410
+ parseServerData(stream) {
12411
+ const protocol = stream.readLong();
12412
+ const serverCount = stream.readLong();
12413
+ const attractLoop = stream.readByte();
12414
+ const gameDir = stream.readString();
12415
+ const playerNum = stream.readShort();
12416
+ const levelName = stream.readString();
12417
+ return {
12418
+ protocol,
12419
+ serverCount,
12420
+ attractLoop,
12421
+ gameDir,
12422
+ playerNum,
12423
+ levelName
12424
+ };
12425
+ }
12426
+ parseEntityBits(stream) {
12427
+ let total = stream.readByte();
12428
+ if (total & shared.U_MOREBITS1) total |= stream.readByte() << 8;
12429
+ if (total & shared.U_MOREBITS2) total |= stream.readByte() << 16;
12430
+ if (total & shared.U_MOREBITS3) total |= stream.readByte() << 24;
12431
+ let number;
12432
+ if (total & shared.U_NUMBER16) number = stream.readShort();
12433
+ else number = stream.readByte();
12434
+ return { number, bits: total, bitsHigh: 0 };
12435
+ }
12436
+ parseDelta(from, to, number, bits, bitsHigh, stream) {
12437
+ to.number = from.number;
12438
+ to.modelindex = from.modelindex;
12439
+ to.modelindex2 = from.modelindex2;
12440
+ to.modelindex3 = from.modelindex3;
12441
+ to.modelindex4 = from.modelindex4;
12442
+ to.frame = from.frame;
12443
+ to.skinnum = from.skinnum;
12444
+ to.effects = from.effects;
12445
+ to.renderfx = from.renderfx;
12446
+ to.origin.x = from.origin.x;
12447
+ to.origin.y = from.origin.y;
12448
+ to.origin.z = from.origin.z;
12449
+ to.old_origin.x = from.origin.x;
12450
+ to.old_origin.y = from.origin.y;
12451
+ to.old_origin.z = from.origin.z;
12452
+ to.angles.x = from.angles.x;
12453
+ to.angles.y = from.angles.y;
12454
+ to.angles.z = from.angles.z;
12455
+ to.sound = from.sound;
12456
+ to.event = from.event;
12457
+ to.solid = from.solid;
12458
+ to.number = number;
12459
+ to.bits = bits;
12460
+ if (bits & shared.U_MODEL) to.modelindex = stream.readByte();
12461
+ if (bits & shared.U_MODEL2) to.modelindex2 = stream.readByte();
12462
+ if (bits & shared.U_MODEL3) to.modelindex3 = stream.readByte();
12463
+ if (bits & shared.U_MODEL4) to.modelindex4 = stream.readByte();
12464
+ if (bits & shared.U_FRAME8) to.frame = stream.readByte();
12465
+ if (bits & shared.U_FRAME16) to.frame = stream.readShort();
12466
+ if (bits & shared.U_SKIN8 && bits & shared.U_SKIN16) to.skinnum = stream.readLong();
12467
+ else if (bits & shared.U_SKIN8) to.skinnum = stream.readByte();
12468
+ else if (bits & shared.U_SKIN16) to.skinnum = stream.readShort();
12469
+ if (bits & shared.U_EFFECTS8 && bits & shared.U_EFFECTS16) to.effects = stream.readLong();
12470
+ else if (bits & shared.U_EFFECTS8) to.effects = stream.readByte();
12471
+ else if (bits & shared.U_EFFECTS16) to.effects = stream.readShort();
12472
+ if (bits & shared.U_RENDERFX8 && bits & shared.U_RENDERFX16) to.renderfx = stream.readLong();
12473
+ else if (bits & shared.U_RENDERFX8) to.renderfx = stream.readByte();
12474
+ else if (bits & shared.U_RENDERFX16) to.renderfx = stream.readShort();
12475
+ if (bits & shared.U_ORIGIN1) to.origin.x = stream.readShort() * 0.125;
12476
+ if (bits & shared.U_ORIGIN2) to.origin.y = stream.readShort() * 0.125;
12477
+ if (bits & shared.U_ORIGIN3) to.origin.z = stream.readShort() * 0.125;
12478
+ if (bits & shared.U_ANGLE1) to.angles.x = stream.readByte() * (360 / 256);
12479
+ if (bits & shared.U_ANGLE2) to.angles.y = stream.readByte() * (360 / 256);
12480
+ if (bits & shared.U_ANGLE3) to.angles.z = stream.readByte() * (360 / 256);
12481
+ if (bits & shared.U_OLDORIGIN) {
12482
+ to.old_origin.x = stream.readShort() * 0.125;
12483
+ to.old_origin.y = stream.readShort() * 0.125;
12484
+ to.old_origin.z = stream.readShort() * 0.125;
12485
+ }
12486
+ if (bits & shared.U_SOUND) to.sound = stream.readByte();
12487
+ if (bits & shared.U_EVENT) to.event = stream.readByte();
12488
+ else to.event = 0;
12489
+ if (bits & shared.U_SOLID) to.solid = stream.readShort();
12490
+ }
12491
+ parsePlayerState(stream) {
12492
+ const ps = createEmptyProtocolPlayerState();
12493
+ const flags = stream.readShort();
12494
+ if (flags & 1) ps.pm_type = stream.readByte();
12495
+ if (flags & 2) {
12496
+ ps.origin.x = stream.readShort() * 0.125;
12497
+ ps.origin.y = stream.readShort() * 0.125;
12498
+ ps.origin.z = stream.readShort() * 0.125;
12499
+ }
12500
+ if (flags & 4) {
12501
+ ps.velocity.x = stream.readShort() * 0.125;
12502
+ ps.velocity.y = stream.readShort() * 0.125;
12503
+ ps.velocity.z = stream.readShort() * 0.125;
12504
+ }
12505
+ if (flags & 8) ps.pm_time = stream.readByte();
12506
+ if (flags & 16) ps.pm_flags = stream.readByte();
12507
+ if (flags & 32) ps.gravity = stream.readShort();
12508
+ if (flags & 64) {
12509
+ ps.delta_angles.x = stream.readShort() * (180 / 32768);
12510
+ ps.delta_angles.y = stream.readShort() * (180 / 32768);
12511
+ ps.delta_angles.z = stream.readShort() * (180 / 32768);
12512
+ }
12513
+ if (flags & 128) {
12514
+ ps.viewoffset.x = (stream.readByte() << 24 >> 24) * 0.25;
12515
+ ps.viewoffset.y = (stream.readByte() << 24 >> 24) * 0.25;
12516
+ ps.viewoffset.z = (stream.readByte() << 24 >> 24) * 0.25;
12517
+ }
12518
+ if (flags & 256) {
12519
+ ps.viewangles.x = stream.readShort() * (360 / 65536);
12520
+ ps.viewangles.y = stream.readShort() * (360 / 65536);
12521
+ ps.viewangles.z = stream.readShort() * (360 / 65536);
12522
+ }
12523
+ if (flags & 512) {
12524
+ ps.kick_angles.x = (stream.readByte() << 24 >> 24) * 0.25;
12525
+ ps.kick_angles.y = (stream.readByte() << 24 >> 24) * 0.25;
12526
+ ps.kick_angles.z = (stream.readByte() << 24 >> 24) * 0.25;
12527
+ }
12528
+ if (flags & 4096) ps.gun_index = stream.readByte();
12529
+ if (flags & 8192) {
12530
+ ps.gun_frame = stream.readByte();
12531
+ ps.gun_offset.x = (stream.readByte() << 24 >> 24) * 0.25;
12532
+ ps.gun_offset.y = (stream.readByte() << 24 >> 24) * 0.25;
12533
+ ps.gun_offset.z = (stream.readByte() << 24 >> 24) * 0.25;
12534
+ ps.gun_angles.x = (stream.readByte() << 24 >> 24) * 0.25;
12535
+ ps.gun_angles.y = (stream.readByte() << 24 >> 24) * 0.25;
12536
+ ps.gun_angles.z = (stream.readByte() << 24 >> 24) * 0.25;
12537
+ }
12538
+ if (flags & 1024) {
12539
+ ps.blend[0] = stream.readByte();
12540
+ ps.blend[1] = stream.readByte();
12541
+ ps.blend[2] = stream.readByte();
12542
+ ps.blend[3] = stream.readByte();
12543
+ }
12544
+ if (flags & 2048) ps.fov = stream.readByte();
12545
+ if (flags & 16384) ps.rdflags = stream.readByte();
12546
+ if (flags & 32768) ps.watertype = stream.readByte();
12547
+ const statbits = stream.readLong();
12548
+ for (let i = 0; i < 32; i++) {
12549
+ if (statbits & 1 << i) ps.stats[i] = stream.readShort();
12550
+ }
12551
+ return ps;
12552
+ }
12553
+ };
12554
+ var BootstrapProtocolHandler = class {
12555
+ constructor() {
12556
+ this.protocolVersion = 0;
12557
+ }
12558
+ // We assume standard Q2 opcodes for bootstrap to find serverdata
12559
+ // but we can also check for legacy serverdata (12 vs 13 vs 7)
12560
+ translateCommand(cmd) {
12561
+ if (cmd === 7) return shared.ServerCommand.serverdata;
12562
+ if (cmd === 12) return shared.ServerCommand.serverdata;
12563
+ if (cmd === 13) return shared.ServerCommand.serverdata;
12564
+ if (cmd === shared.ServerCommand.stufftext) return shared.ServerCommand.stufftext;
12565
+ return shared.ServerCommand.bad;
12566
+ }
12567
+ parseServerData(stream) {
12568
+ const protocol = stream.readLong();
12569
+ if (protocol === PROTOCOL_VERSION_RERELEASE) {
12570
+ const spawnCount = stream.readLong();
12571
+ const demoType = stream.readByte();
12572
+ const tickRate = stream.readByte();
12573
+ const gameDir = stream.readString();
12574
+ let playerNum = stream.readShort();
12575
+ if (playerNum === -2) {
12576
+ const numSplits = stream.readShort();
12577
+ for (let i = 0; i < numSplits; i++) stream.readShort();
12578
+ playerNum = 0;
12579
+ } else if (playerNum === -1) {
12580
+ playerNum = -1;
12581
+ }
12582
+ const levelName = stream.readString();
12583
+ return {
12584
+ protocol,
12585
+ serverCount: spawnCount,
12586
+ spawnCount,
12587
+ attractLoop: 0,
12588
+ gameDir,
12589
+ playerNum,
12590
+ levelName,
12591
+ tickRate,
12592
+ demoType
12593
+ };
12594
+ } else {
12595
+ const serverCount = stream.readLong();
12596
+ const attractLoop = stream.readByte();
12597
+ const gameDir = stream.readString();
12598
+ const playerNum = stream.readShort();
12599
+ const levelName = stream.readString();
12600
+ return {
12601
+ protocol,
12602
+ serverCount,
12603
+ attractLoop,
12604
+ gameDir,
12605
+ playerNum,
12606
+ levelName
12607
+ };
12608
+ }
12609
+ }
12610
+ parseEntityBits(stream) {
12611
+ throw new Error("Bootstrap handler cannot parse entities");
12612
+ }
12613
+ parseDelta(from, to, number, bits, bitsHigh, stream) {
12614
+ throw new Error("Bootstrap handler cannot parse delta");
12615
+ }
12616
+ parsePlayerState(stream) {
12617
+ throw new Error("Bootstrap handler cannot parse player state");
12618
+ }
12619
+ };
12620
+ function createProtocolHandler(version) {
12621
+ if (version === 0) {
12622
+ return new BootstrapProtocolHandler();
12623
+ }
12624
+ if (version === PROTOCOL_VERSION_RERELEASE) {
12625
+ return new RereleaseProtocolHandler();
12626
+ }
12627
+ if (version === 34) {
12628
+ return new Quake2ProtocolHandler();
12629
+ }
12630
+ return new LegacyProtocolHandler(version);
12631
+ }
12632
+ var RECORD_CLIENT = 1;
12633
+ var RECORD_SERVER = 2;
12634
+ var RECORD_RELAY = 128;
12105
12635
  var BinaryStreamAdapter = class extends StreamingBuffer {
12106
12636
  constructor(stream) {
12107
12637
  super(0);
@@ -12139,38 +12669,11 @@ var BinaryStreamAdapter = class extends StreamingBuffer {
12139
12669
  throw new Error("peekBytes not implemented for BinaryStreamAdapter");
12140
12670
  }
12141
12671
  };
12142
- var PROTO34_MAP = {
12143
- 0: shared.ServerCommand.bad,
12144
- 1: shared.ServerCommand.nop,
12145
- 2: shared.ServerCommand.disconnect,
12146
- 3: shared.ServerCommand.reconnect,
12147
- 4: shared.ServerCommand.download,
12148
- 5: shared.ServerCommand.frame,
12149
- 6: shared.ServerCommand.inventory,
12150
- 7: shared.ServerCommand.layout,
12151
- 8: shared.ServerCommand.muzzleflash,
12152
- 9: shared.ServerCommand.sound,
12153
- 10: shared.ServerCommand.print,
12154
- 11: shared.ServerCommand.stufftext,
12155
- 12: shared.ServerCommand.serverdata,
12156
- 13: shared.ServerCommand.configstring,
12157
- 14: shared.ServerCommand.spawnbaseline,
12158
- 15: shared.ServerCommand.centerprint,
12159
- 16: shared.ServerCommand.download,
12160
- 17: shared.ServerCommand.playerinfo,
12161
- 18: shared.ServerCommand.packetentities,
12162
- 19: shared.ServerCommand.deltapacketentities,
12163
- 23: shared.ServerCommand.temp_entity,
12164
- // Wire 23 -> Enum 3 (TempEntity)
12165
- 22: shared.ServerCommand.muzzleflash2
12166
- // Wire 22 -> Enum 2 (MuzzleFlash2)
12167
- };
12168
12672
  var NetworkMessageParser = class _NetworkMessageParser {
12169
12673
  constructor(stream, handler, strictMode = false) {
12170
- this.protocolVersion = 0;
12171
- this.isDemo = RECORD_CLIENT;
12172
12674
  this.strictMode = false;
12173
12675
  this.errorCount = 0;
12676
+ this.isDemo = RECORD_CLIENT;
12174
12677
  if (stream instanceof shared.BinaryStream) {
12175
12678
  this.stream = new BinaryStreamAdapter(stream);
12176
12679
  } else {
@@ -12178,41 +12681,19 @@ var NetworkMessageParser = class _NetworkMessageParser {
12178
12681
  }
12179
12682
  this.handler = handler;
12180
12683
  this.strictMode = strictMode;
12684
+ this.protocolHandler = new BootstrapProtocolHandler();
12181
12685
  }
12182
12686
  setProtocolVersion(version) {
12183
- this.protocolVersion = version;
12687
+ if (this.protocolHandler.protocolVersion !== version) {
12688
+ this.protocolHandler = createProtocolHandler(version);
12689
+ }
12184
12690
  }
12185
12691
  getProtocolVersion() {
12186
- return this.protocolVersion;
12692
+ return this.protocolHandler.protocolVersion;
12187
12693
  }
12188
12694
  getErrorCount() {
12189
12695
  return this.errorCount;
12190
12696
  }
12191
- translateCommand(cmd) {
12192
- if (this.protocolVersion === 0) {
12193
- if (cmd === 7) return shared.ServerCommand.serverdata;
12194
- if (cmd === 12) return shared.ServerCommand.serverdata;
12195
- return cmd;
12196
- }
12197
- if (this.protocolVersion === PROTOCOL_VERSION_RERELEASE) {
12198
- return cmd;
12199
- }
12200
- if (this.protocolVersion === 25 || this.protocolVersion === 26) {
12201
- if (cmd === 0) return shared.ServerCommand.bad;
12202
- const translated = cmd + 5;
12203
- if (translated >= shared.ServerCommand.nop && translated <= shared.ServerCommand.frame) {
12204
- return translated;
12205
- }
12206
- return shared.ServerCommand.bad;
12207
- }
12208
- if (this.protocolVersion === 34) {
12209
- if (PROTO34_MAP[cmd] !== void 0) {
12210
- return PROTO34_MAP[cmd];
12211
- }
12212
- return shared.ServerCommand.bad;
12213
- }
12214
- return cmd;
12215
- }
12216
12697
  parseMessage() {
12217
12698
  while (this.stream.hasBytes(1)) {
12218
12699
  const startPos = this.stream.getReadPosition();
@@ -12221,9 +12702,16 @@ var NetworkMessageParser = class _NetworkMessageParser {
12221
12702
  cmd = this.stream.readByte();
12222
12703
  if (cmd === -1) break;
12223
12704
  const originalCmd = cmd;
12224
- cmd = this.translateCommand(cmd);
12225
- switch (cmd) {
12705
+ const translatedCmd = this.protocolHandler.translateCommand(cmd);
12706
+ switch (translatedCmd) {
12226
12707
  case shared.ServerCommand.bad:
12708
+ if (originalCmd === 0) {
12709
+ return;
12710
+ }
12711
+ const errorMsg = `Unknown server command: ${originalCmd} (translated: ${translatedCmd}) at offset ${startPos} (Protocol: ${this.getProtocolVersion()})`;
12712
+ if (this.strictMode) throw new Error(errorMsg);
12713
+ console.warn(errorMsg);
12714
+ this.errorCount++;
12227
12715
  return;
12228
12716
  case shared.ServerCommand.nop:
12229
12717
  break;
@@ -12324,9 +12812,9 @@ var NetworkMessageParser = class _NetworkMessageParser {
12324
12812
  this.parseAchievement();
12325
12813
  break;
12326
12814
  default:
12327
- const errorMsg = `Unknown server command: ${originalCmd} (translated: ${cmd}) at offset ${startPos}`;
12328
- if (this.strictMode) throw new Error(errorMsg);
12329
- console.warn(errorMsg);
12815
+ const errorMsgDef = `Unknown server command: ${originalCmd} (translated: ${translatedCmd}) at offset ${startPos}`;
12816
+ if (this.strictMode) throw new Error(errorMsgDef);
12817
+ console.warn(errorMsgDef);
12330
12818
  this.errorCount++;
12331
12819
  return;
12332
12820
  }
@@ -12340,7 +12828,7 @@ var NetworkMessageParser = class _NetworkMessageParser {
12340
12828
  }
12341
12829
  return;
12342
12830
  }
12343
- const context = `offset ${startPos}, cmd ${cmd}, protocol ${this.protocolVersion}`;
12831
+ const context = `offset ${startPos}, cmd ${cmd}, protocol ${this.getProtocolVersion()}`;
12344
12832
  console.warn(`Error parsing command ${cmd} (${context}): ${errMsg}`);
12345
12833
  this.errorCount++;
12346
12834
  if (this.strictMode) throw e;
@@ -12393,31 +12881,24 @@ var NetworkMessageParser = class _NetworkMessageParser {
12393
12881
  if (this.handler) this.handler.onCenterPrint(centerMsg);
12394
12882
  }
12395
12883
  parseServerData() {
12396
- this.protocolVersion = this.stream.readLong();
12397
- if (this.protocolVersion === PROTOCOL_VERSION_RERELEASE) {
12398
- const spawnCount = this.stream.readLong();
12399
- const demoType = this.stream.readByte();
12400
- this.isDemo = demoType;
12401
- const tickRate = this.stream.readByte();
12402
- const gameDir = this.stream.readString();
12403
- let playerNum = this.stream.readShort();
12404
- if (playerNum === -2) {
12405
- const numSplits = this.stream.readShort();
12406
- for (let i = 0; i < numSplits; i++) this.stream.readShort();
12407
- playerNum = 0;
12408
- } else if (playerNum === -1) {
12409
- playerNum = -1;
12410
- }
12411
- const levelName = this.stream.readString();
12412
- if (this.handler) this.handler.onServerData(this.protocolVersion, spawnCount, 0, gameDir, playerNum, levelName, tickRate, demoType);
12884
+ const data = this.protocolHandler.parseServerData(this.stream);
12885
+ this.setProtocolVersion(data.protocol);
12886
+ if (this.handler) {
12887
+ this.handler.onServerData(
12888
+ data.protocol,
12889
+ data.serverCount,
12890
+ data.attractLoop,
12891
+ data.gameDir,
12892
+ data.playerNum,
12893
+ data.levelName,
12894
+ data.tickRate,
12895
+ data.demoType
12896
+ );
12897
+ }
12898
+ if (data.protocol === PROTOCOL_VERSION_RERELEASE) {
12899
+ this.isDemo = data.demoType ?? RECORD_CLIENT;
12413
12900
  } else {
12414
- const serverCount = this.stream.readLong();
12415
- const attractLoop = this.stream.readByte();
12416
- this.isDemo = attractLoop;
12417
- const gameDir = this.stream.readString();
12418
- const playerNum = this.stream.readShort();
12419
- const levelName = this.stream.readString();
12420
- if (this.handler) this.handler.onServerData(this.protocolVersion, serverCount, attractLoop, gameDir, playerNum, levelName);
12901
+ this.isDemo = data.attractLoop;
12421
12902
  }
12422
12903
  }
12423
12904
  parseConfigString() {
@@ -12453,7 +12934,7 @@ var NetworkMessageParser = class _NetworkMessageParser {
12453
12934
  const decompressed = pako.inflate(compressedData);
12454
12935
  const blastStream = new shared.BinaryStream(decompressed.buffer);
12455
12936
  const blastParser = new _NetworkMessageParser(blastStream, this.handler, this.strictMode);
12456
- blastParser.setProtocolVersion(this.protocolVersion);
12937
+ blastParser.setProtocolVersion(this.getProtocolVersion());
12457
12938
  while (blastStream.hasMore()) {
12458
12939
  blastParser.parseSpawnBaseline();
12459
12940
  }
@@ -12649,7 +13130,7 @@ var NetworkMessageParser = class _NetworkMessageParser {
12649
13130
  color = this.stream.readByte();
12650
13131
  break;
12651
13132
  case shared.TempEntity.BLUEHYPERBLASTER:
12652
- if (this.protocolVersion >= 32) {
13133
+ if (this.getProtocolVersion() >= 32) {
12653
13134
  this.readPos(pos);
12654
13135
  this.readPos(pos2);
12655
13136
  } else {
@@ -12658,7 +13139,7 @@ var NetworkMessageParser = class _NetworkMessageParser {
12658
13139
  }
12659
13140
  break;
12660
13141
  case shared.TempEntity.GREENBLOOD:
12661
- if (this.protocolVersion >= 32) {
13142
+ if (this.getProtocolVersion() >= 32) {
12662
13143
  this.readPos(pos);
12663
13144
  this.readDir(dir);
12664
13145
  } else {
@@ -12723,29 +13204,29 @@ var NetworkMessageParser = class _NetworkMessageParser {
12723
13204
  if (this.handler) this.handler.onTempEntity(type, pos, pos2, dir, cnt, color, ent, srcEnt, destEnt);
12724
13205
  }
12725
13206
  parseSpawnBaseline() {
12726
- const bits = this.parseEntityBits();
13207
+ const bits = this.protocolHandler.parseEntityBits(this.stream);
12727
13208
  const entity = createEmptyEntityState();
12728
- this.parseDelta(createEmptyEntityState(), entity, bits.number, bits.bits, bits.bitsHigh);
13209
+ this.protocolHandler.parseDelta(createEmptyEntityState(), entity, bits.number, bits.bits, bits.bitsHigh, this.stream);
12729
13210
  if (this.handler) this.handler.onSpawnBaseline(entity);
12730
13211
  }
12731
13212
  parseFrame() {
12732
13213
  const serverFrame = this.stream.readLong();
12733
13214
  const deltaFrame = this.stream.readLong();
12734
13215
  let surpressCount = 0;
12735
- if (this.protocolVersion !== 26 && this.protocolVersion !== 25) {
13216
+ if (this.getProtocolVersion() !== 26 && this.getProtocolVersion() !== 25) {
12736
13217
  surpressCount = this.stream.readByte();
12737
13218
  }
12738
13219
  const areaBytes = this.stream.readByte();
12739
13220
  const areaBits = this.stream.readData(areaBytes);
12740
13221
  let piCmd = this.stream.readByte();
12741
- piCmd = this.translateCommand(piCmd);
13222
+ piCmd = this.protocolHandler.translateCommand(piCmd);
12742
13223
  if (piCmd !== shared.ServerCommand.playerinfo) {
12743
13224
  if (this.strictMode) throw new Error(`Expected svc_playerinfo after svc_frame, got ${piCmd}`);
12744
13225
  return;
12745
13226
  }
12746
13227
  const playerState = this.parsePlayerState();
12747
13228
  let peCmd = this.stream.readByte();
12748
- peCmd = this.translateCommand(peCmd);
13229
+ peCmd = this.protocolHandler.translateCommand(peCmd);
12749
13230
  if (peCmd !== shared.ServerCommand.packetentities && peCmd !== shared.ServerCommand.deltapacketentities) {
12750
13231
  if (this.strictMode) throw new Error(`Expected svc_packetentities after svc_playerinfo, got ${peCmd}`);
12751
13232
  return;
@@ -12767,64 +13248,7 @@ var NetworkMessageParser = class _NetworkMessageParser {
12767
13248
  });
12768
13249
  }
12769
13250
  parsePlayerState() {
12770
- const ps = createEmptyProtocolPlayerState();
12771
- const flags = this.stream.readShort();
12772
- if (flags & 1) ps.pm_type = this.stream.readByte();
12773
- if (flags & 2) {
12774
- ps.origin.x = this.readCoord();
12775
- ps.origin.y = this.readCoord();
12776
- ps.origin.z = this.readCoord();
12777
- }
12778
- if (flags & 4) {
12779
- ps.velocity.x = this.readCoord();
12780
- ps.velocity.y = this.readCoord();
12781
- ps.velocity.z = this.readCoord();
12782
- }
12783
- if (flags & 8) ps.pm_time = this.stream.readByte();
12784
- if (flags & 16) ps.pm_flags = this.stream.readByte();
12785
- if (flags & 32) ps.gravity = this.stream.readShort();
12786
- if (flags & 64) {
12787
- ps.delta_angles.x = this.stream.readShort() * (180 / 32768);
12788
- ps.delta_angles.y = this.stream.readShort() * (180 / 32768);
12789
- ps.delta_angles.z = this.stream.readShort() * (180 / 32768);
12790
- }
12791
- if (flags & 128) {
12792
- ps.viewoffset.x = (this.stream.readByte() << 24 >> 24) * 0.25;
12793
- ps.viewoffset.y = (this.stream.readByte() << 24 >> 24) * 0.25;
12794
- ps.viewoffset.z = (this.stream.readByte() << 24 >> 24) * 0.25;
12795
- }
12796
- if (flags & 256) {
12797
- ps.viewangles.x = this.readAngle16();
12798
- ps.viewangles.y = this.readAngle16();
12799
- ps.viewangles.z = this.readAngle16();
12800
- }
12801
- if (flags & 512) {
12802
- ps.kick_angles.x = (this.stream.readByte() << 24 >> 24) * 0.25;
12803
- ps.kick_angles.y = (this.stream.readByte() << 24 >> 24) * 0.25;
12804
- ps.kick_angles.z = (this.stream.readByte() << 24 >> 24) * 0.25;
12805
- }
12806
- if (flags & 4096) ps.gun_index = this.stream.readByte();
12807
- if (flags & 8192) {
12808
- ps.gun_frame = this.stream.readByte();
12809
- ps.gun_offset.x = (this.stream.readByte() << 24 >> 24) * 0.25;
12810
- ps.gun_offset.y = (this.stream.readByte() << 24 >> 24) * 0.25;
12811
- ps.gun_offset.z = (this.stream.readByte() << 24 >> 24) * 0.25;
12812
- ps.gun_angles.x = (this.stream.readByte() << 24 >> 24) * 0.25;
12813
- ps.gun_angles.y = (this.stream.readByte() << 24 >> 24) * 0.25;
12814
- ps.gun_angles.z = (this.stream.readByte() << 24 >> 24) * 0.25;
12815
- }
12816
- if (flags & 1024) {
12817
- ps.blend[0] = this.stream.readByte();
12818
- ps.blend[1] = this.stream.readByte();
12819
- ps.blend[2] = this.stream.readByte();
12820
- ps.blend[3] = this.stream.readByte();
12821
- }
12822
- if (flags & 2048) ps.fov = this.stream.readByte();
12823
- if (flags & 16384) ps.rdflags = this.stream.readByte();
12824
- if (flags & 32768) ps.watertype = this.stream.readByte();
12825
- const statbits = this.stream.readLong();
12826
- for (let i = 0; i < 32; i++) if (statbits & 1 << i) ps.stats[i] = this.stream.readShort();
12827
- return ps;
13251
+ return this.protocolHandler.parsePlayerState(this.stream);
12828
13252
  }
12829
13253
  parsePacketEntities(delta) {
12830
13254
  const entities = this.collectPacketEntities();
@@ -12841,103 +13265,20 @@ var NetworkMessageParser = class _NetworkMessageParser {
12841
13265
  collectPacketEntities() {
12842
13266
  const entities = [];
12843
13267
  while (true) {
12844
- const bits = this.parseEntityBits();
12845
- if (bits.bits & U_REMOVE) {
13268
+ const bits = this.protocolHandler.parseEntityBits(this.stream);
13269
+ if (bits.bits & shared.U_REMOVE) {
12846
13270
  if (bits.number === 0) break;
12847
13271
  continue;
12848
13272
  }
12849
13273
  const entity = createEmptyEntityState();
12850
- const forceParse = bits.number === 0 && !(bits.bits & U_MOREBITS1);
12851
- if (bits.number !== 0 || forceParse) {
12852
- this.parseDelta(createEmptyEntityState(), entity, bits.number, bits.bits, bits.bitsHigh);
13274
+ if (bits.number === 0) {
13275
+ break;
12853
13276
  }
12854
- if (bits.number === 0) break;
13277
+ this.protocolHandler.parseDelta(createEmptyEntityState(), entity, bits.number, bits.bits, bits.bitsHigh, this.stream);
12855
13278
  entities.push(entity);
12856
13279
  }
12857
13280
  return entities;
12858
13281
  }
12859
- parseEntityBits() {
12860
- let total = this.stream.readByte();
12861
- if (total & U_MOREBITS1) total |= this.stream.readByte() << 8;
12862
- if (total & U_MOREBITS2) total |= this.stream.readByte() << 16;
12863
- if (total & U_MOREBITS3) total |= this.stream.readByte() << 24;
12864
- let bitsHigh = 0;
12865
- if (this.protocolVersion === PROTOCOL_VERSION_RERELEASE) {
12866
- if (total & U_MOREBITS4) bitsHigh = this.stream.readByte();
12867
- }
12868
- let number;
12869
- if (total & U_NUMBER16) number = this.stream.readShort();
12870
- else number = this.stream.readByte();
12871
- return { number, bits: total, bitsHigh };
12872
- }
12873
- parseDelta(from, to, number, bits, bitsHigh = 0) {
12874
- to.number = from.number;
12875
- to.modelindex = from.modelindex;
12876
- to.modelindex2 = from.modelindex2;
12877
- to.modelindex3 = from.modelindex3;
12878
- to.modelindex4 = from.modelindex4;
12879
- to.frame = from.frame;
12880
- to.skinnum = from.skinnum;
12881
- to.effects = from.effects;
12882
- to.renderfx = from.renderfx;
12883
- to.origin.x = from.origin.x;
12884
- to.origin.y = from.origin.y;
12885
- to.origin.z = from.origin.z;
12886
- to.old_origin.x = from.origin.x;
12887
- to.old_origin.y = from.origin.y;
12888
- to.old_origin.z = from.origin.z;
12889
- to.angles.x = from.angles.x;
12890
- to.angles.y = from.angles.y;
12891
- to.angles.z = from.angles.z;
12892
- to.sound = from.sound;
12893
- to.event = from.event;
12894
- to.solid = from.solid;
12895
- to.alpha = from.alpha;
12896
- to.scale = from.scale;
12897
- to.instanceBits = from.instanceBits;
12898
- to.loopVolume = from.loopVolume;
12899
- to.loopAttenuation = from.loopAttenuation;
12900
- to.owner = from.owner;
12901
- to.oldFrame = from.oldFrame;
12902
- to.number = number;
12903
- to.bits = bits;
12904
- to.bitsHigh = bitsHigh;
12905
- if (bits & U_MODEL) to.modelindex = this.stream.readByte();
12906
- if (bits & U_MODEL2) to.modelindex2 = this.stream.readByte();
12907
- if (bits & U_MODEL3) to.modelindex3 = this.stream.readByte();
12908
- if (bits & U_MODEL4) to.modelindex4 = this.stream.readByte();
12909
- if (bits & U_FRAME8) to.frame = this.stream.readByte();
12910
- if (bits & U_FRAME16) to.frame = this.stream.readShort();
12911
- if (bits & U_SKIN8 && bits & U_SKIN16) to.skinnum = this.stream.readLong();
12912
- else if (bits & U_SKIN8) to.skinnum = this.stream.readByte();
12913
- else if (bits & U_SKIN16) to.skinnum = this.stream.readShort();
12914
- if (bits & U_EFFECTS8 && bits & U_EFFECTS16) to.effects = this.stream.readLong();
12915
- else if (bits & U_EFFECTS8) to.effects = this.stream.readByte();
12916
- else if (bits & U_EFFECTS16) to.effects = this.stream.readShort();
12917
- if (bits & U_RENDERFX8 && bits & U_RENDERFX16) to.renderfx = this.stream.readLong();
12918
- else if (bits & U_RENDERFX8) to.renderfx = this.stream.readByte();
12919
- else if (bits & U_RENDERFX16) to.renderfx = this.stream.readShort();
12920
- if (bits & U_ORIGIN1) to.origin.x = this.readCoord();
12921
- if (bits & U_ORIGIN2) to.origin.y = this.readCoord();
12922
- if (bits & U_ORIGIN3) to.origin.z = this.readCoord();
12923
- if (bits & U_ANGLE1) to.angles.x = this.readAngle();
12924
- if (bits & U_ANGLE2) to.angles.y = this.readAngle();
12925
- if (bits & U_ANGLE3) to.angles.z = this.readAngle();
12926
- if (bits & U_OLDORIGIN) this.readPos(to.old_origin);
12927
- if (bits & U_SOUND) to.sound = this.stream.readByte();
12928
- if (bits & U_EVENT) to.event = this.stream.readByte();
12929
- else to.event = 0;
12930
- if (bits & U_SOLID) to.solid = this.stream.readShort();
12931
- if (this.protocolVersion === PROTOCOL_VERSION_RERELEASE) {
12932
- if (bits & U_ALPHA) to.alpha = this.stream.readByte() / 255;
12933
- if (bits & U_SCALE) to.scale = this.stream.readFloat();
12934
- if (bits & U_INSTANCE_BITS) to.instanceBits = this.stream.readLong();
12935
- if (bits & U_LOOP_VOLUME) to.loopVolume = this.stream.readByte() / 255;
12936
- if (bitsHigh & U_LOOP_ATTENUATION_HIGH) to.loopAttenuation = this.stream.readByte() / 255;
12937
- if (bitsHigh & U_OWNER_HIGH) to.owner = this.stream.readShort();
12938
- if (bitsHigh & U_OLD_FRAME_HIGH) to.oldFrame = this.stream.readShort();
12939
- }
12940
- }
12941
13282
  };
12942
13283
 
12943
13284
  // src/demo/analysis.ts
@@ -13203,12 +13544,12 @@ var DemoCameraMode = /* @__PURE__ */ ((DemoCameraMode2) => {
13203
13544
  })(DemoCameraMode || {});
13204
13545
 
13205
13546
  // src/demo/playback.ts
13206
- var PlaybackState = /* @__PURE__ */ ((PlaybackState3) => {
13207
- PlaybackState3[PlaybackState3["Stopped"] = 0] = "Stopped";
13208
- PlaybackState3[PlaybackState3["Playing"] = 1] = "Playing";
13209
- PlaybackState3[PlaybackState3["Paused"] = 2] = "Paused";
13210
- PlaybackState3[PlaybackState3["Finished"] = 3] = "Finished";
13211
- return PlaybackState3;
13547
+ var PlaybackState = /* @__PURE__ */ ((PlaybackState2) => {
13548
+ PlaybackState2[PlaybackState2["Stopped"] = 0] = "Stopped";
13549
+ PlaybackState2[PlaybackState2["Playing"] = 1] = "Playing";
13550
+ PlaybackState2[PlaybackState2["Paused"] = 2] = "Paused";
13551
+ PlaybackState2[PlaybackState2["Finished"] = 3] = "Finished";
13552
+ return PlaybackState2;
13212
13553
  })(PlaybackState || {});
13213
13554
  var createNoOpHandler = () => ({
13214
13555
  onServerData: () => {
@@ -13929,289 +14270,134 @@ var DemoRecorder = class {
13929
14270
  return this.isRecording;
13930
14271
  }
13931
14272
  };
13932
- var PROTO34_REVERSE_MAP = {
13933
- [shared.ServerCommand.bad]: 0,
13934
- [shared.ServerCommand.nop]: 1,
13935
- [shared.ServerCommand.disconnect]: 2,
13936
- [shared.ServerCommand.reconnect]: 3,
13937
- // 4 is download? standard Q2 uses 4 for download sometimes, but let's stick to parser map (download=16).
13938
- // Let's map download to 16.
13939
- [shared.ServerCommand.download]: 16,
13940
- [shared.ServerCommand.frame]: 5,
13941
- [shared.ServerCommand.inventory]: 6,
13942
- [shared.ServerCommand.layout]: 7,
13943
- [shared.ServerCommand.muzzleflash]: 8,
13944
- [shared.ServerCommand.sound]: 9,
13945
- [shared.ServerCommand.print]: 10,
13946
- [shared.ServerCommand.stufftext]: 11,
13947
- [shared.ServerCommand.serverdata]: 12,
13948
- [shared.ServerCommand.configstring]: 13,
13949
- [shared.ServerCommand.spawnbaseline]: 14,
13950
- [shared.ServerCommand.centerprint]: 15,
13951
- // 16 is download
13952
- [shared.ServerCommand.playerinfo]: 17,
13953
- [shared.ServerCommand.packetentities]: 18,
13954
- [shared.ServerCommand.deltapacketentities]: 19,
13955
- // Temp entity? Standard Q2 uses 9 for temp_entity?
13956
- // But we mapped 9 to sound.
13957
- // If we map temp_entity to 23 (arbitrary safe slot for internal tests) or assume standard Q2 layout:
13958
- // Q2: svc_temp_entity = 9. svc_sound = 10.
13959
- // My previous edit to parser.ts used 9->Sound, 10->Print.
13960
- // I should check what I committed to `parser.ts` just now.
13961
- // I committed: 9: Sound, 10: Print.
13962
- // So Writer MUST MATCH Parser.
13963
- // So if Parser says 9 is Sound, Writer must write Sound as 9.
13964
- // But what about TempEntity?
13965
- // Parser does NOT map any wire code to TempEntity in my recent edit (I commented out 23).
13966
- // So TempEntity is currently broken for Protocol 34 unless I map it.
13967
- // I will map TempEntity to 23 in both.
13968
- [shared.ServerCommand.temp_entity]: 23,
13969
- // MuzzleFlash2?
13970
- // I'll map it to 22 (arbitrary) just to have a value, or skip if unused.
13971
- [shared.ServerCommand.muzzleflash2]: 22
13972
- };
13973
14273
  var MessageWriter = class {
13974
- constructor() {
13975
- this.writer = new shared.BinaryWriter();
13976
- }
13977
- getData() {
13978
- return this.writer.getData();
13979
- }
13980
- writeCommand(cmd, protocolVersion = 0) {
13981
- if (protocolVersion === 34) {
13982
- const translated = PROTO34_REVERSE_MAP[cmd];
13983
- if (translated !== void 0) {
13984
- this.writer.writeByte(translated);
13985
- return;
13986
- }
13987
- }
13988
- this.writer.writeByte(cmd);
13989
- }
13990
- writeServerData(protocol, serverCount, attractLoop, gameDir, playerNum, levelName) {
13991
- this.writeCommand(shared.ServerCommand.serverdata, protocol);
13992
- this.writer.writeLong(protocol);
13993
- this.writer.writeLong(serverCount);
13994
- this.writer.writeByte(attractLoop);
13995
- this.writer.writeString(gameDir);
13996
- this.writer.writeShort(playerNum);
13997
- this.writer.writeString(levelName);
13998
- }
13999
- writeServerDataRerelease(protocol, spawnCount, demoType, tickRate, gameDir, playerNum, levelName) {
14000
- this.writeCommand(shared.ServerCommand.serverdata, protocol);
14001
- this.writer.writeLong(protocol);
14002
- this.writer.writeLong(spawnCount);
14003
- this.writer.writeByte(demoType);
14004
- this.writer.writeByte(tickRate);
14005
- this.writer.writeString(gameDir);
14006
- this.writer.writeShort(playerNum);
14007
- this.writer.writeString(levelName);
14008
- }
14009
- writeConfigString(index, str, protocolVersion = 0) {
14010
- this.writeCommand(shared.ServerCommand.configstring, protocolVersion);
14011
- this.writer.writeShort(index);
14012
- this.writer.writeString(str);
14013
- }
14014
- writeSpawnBaseline(entity, protocolVersion) {
14015
- this.writeCommand(shared.ServerCommand.spawnbaseline, protocolVersion);
14016
- this.writeEntityState(entity, null, true, protocolVersion);
14017
- }
14018
- writeStuffText(text, protocolVersion = 0) {
14019
- this.writeCommand(shared.ServerCommand.stufftext, protocolVersion);
14020
- this.writer.writeString(text);
14021
- }
14022
- writeCenterPrint(text, protocolVersion = 0) {
14023
- this.writeCommand(shared.ServerCommand.centerprint, protocolVersion);
14024
- this.writer.writeString(text);
14025
- }
14026
- writePrint(level, text, protocolVersion = 0) {
14027
- this.writeCommand(shared.ServerCommand.print, protocolVersion);
14028
- this.writer.writeByte(level);
14029
- this.writer.writeString(text);
14030
- }
14031
- writeLayout(layout, protocolVersion = 0) {
14032
- this.writeCommand(shared.ServerCommand.layout, protocolVersion);
14033
- this.writer.writeString(layout);
14034
- }
14035
- writeInventory(inventory, protocolVersion = 0) {
14036
- this.writeCommand(shared.ServerCommand.inventory, protocolVersion);
14037
- for (let i = 0; i < 256; i++) {
14038
- this.writer.writeShort(inventory[i] || 0);
14039
- }
14040
- }
14041
- writeMuzzleFlash(ent, weapon, protocolVersion = 0) {
14042
- this.writeCommand(shared.ServerCommand.muzzleflash, protocolVersion);
14043
- this.writer.writeShort(ent);
14044
- this.writer.writeByte(weapon);
14045
- }
14046
- writeMuzzleFlash2(ent, weapon, protocolVersion = 0) {
14047
- this.writeCommand(shared.ServerCommand.muzzleflash2, protocolVersion);
14048
- this.writer.writeShort(ent);
14049
- this.writer.writeByte(weapon);
14050
- }
14051
- writeTempEntity(type, pos, pos2, dir, cnt, color, ent, srcEnt, destEnt, protocolVersion = 0) {
14052
- this.writeCommand(shared.ServerCommand.temp_entity, protocolVersion);
14053
- this.writer.writeByte(type);
14054
- switch (type) {
14055
- case shared.TempEntity.EXPLOSION1:
14056
- case shared.TempEntity.EXPLOSION2:
14057
- case shared.TempEntity.ROCKET_EXPLOSION:
14058
- case shared.TempEntity.GRENADE_EXPLOSION:
14059
- case shared.TempEntity.ROCKET_EXPLOSION_WATER:
14060
- case shared.TempEntity.GRENADE_EXPLOSION_WATER:
14061
- case shared.TempEntity.BFG_EXPLOSION:
14062
- case shared.TempEntity.BFG_BIGEXPLOSION:
14063
- case shared.TempEntity.BOSSTPORT:
14064
- case shared.TempEntity.PLASMA_EXPLOSION:
14065
- case shared.TempEntity.PLAIN_EXPLOSION:
14066
- case shared.TempEntity.CHAINFIST_SMOKE:
14067
- case shared.TempEntity.TRACKER_EXPLOSION:
14068
- case shared.TempEntity.TELEPORT_EFFECT:
14069
- case shared.TempEntity.DBALL_GOAL:
14070
- case shared.TempEntity.NUKEBLAST:
14071
- case shared.TempEntity.WIDOWSPLASH:
14072
- case shared.TempEntity.EXPLOSION1_BIG:
14073
- case shared.TempEntity.EXPLOSION1_NP:
14074
- this.writer.writePos(pos);
14075
- break;
14076
- case shared.TempEntity.GUNSHOT:
14077
- case shared.TempEntity.BLOOD:
14078
- case shared.TempEntity.BLASTER:
14079
- case shared.TempEntity.SHOTGUN:
14080
- case shared.TempEntity.SPARKS:
14081
- case shared.TempEntity.BULLET_SPARKS:
14082
- case shared.TempEntity.SCREEN_SPARKS:
14083
- case shared.TempEntity.SHIELD_SPARKS:
14084
- case shared.TempEntity.BLASTER2:
14085
- case shared.TempEntity.FLECHETTE:
14086
- case shared.TempEntity.MOREBLOOD:
14087
- case shared.TempEntity.ELECTRIC_SPARKS:
14088
- case shared.TempEntity.HEATBEAM_SPARKS:
14089
- case shared.TempEntity.HEATBEAM_STEAM:
14090
- this.writer.writePos(pos);
14091
- this.writer.writeDir(dir || { x: 0, y: 0, z: 0 });
14092
- break;
14093
- case shared.TempEntity.SPLASH:
14094
- case shared.TempEntity.LASER_SPARKS:
14095
- case shared.TempEntity.WELDING_SPARKS:
14096
- case shared.TempEntity.TUNNEL_SPARKS:
14097
- this.writer.writeByte(cnt || 0);
14098
- this.writer.writePos(pos);
14099
- this.writer.writeDir(dir || { x: 0, y: 0, z: 0 });
14100
- this.writer.writeByte(color || 0);
14101
- break;
14102
- case shared.TempEntity.BLUEHYPERBLASTER:
14103
- if (protocolVersion >= 32) {
14104
- this.writer.writePos(pos);
14105
- this.writer.writePos(pos2 || { x: 0, y: 0, z: 0 });
14106
- } else {
14107
- this.writer.writePos(pos);
14108
- this.writer.writeDir(dir || { x: 0, y: 0, z: 0 });
14109
- }
14110
- break;
14111
- case shared.TempEntity.GREENBLOOD:
14112
- if (protocolVersion >= 32) {
14113
- this.writer.writePos(pos);
14114
- this.writer.writeDir(dir || { x: 0, y: 0, z: 0 });
14115
- } else {
14116
- this.writer.writePos(pos);
14117
- this.writer.writePos(pos2 || { x: 0, y: 0, z: 0 });
14118
- }
14119
- break;
14120
- case shared.TempEntity.RAILTRAIL:
14121
- case shared.TempEntity.BUBBLETRAIL:
14122
- case shared.TempEntity.BFG_LASER:
14123
- case shared.TempEntity.DEBUGTRAIL:
14124
- case shared.TempEntity.BUBBLETRAIL2:
14125
- this.writer.writePos(pos);
14126
- this.writer.writePos(pos2 || { x: 0, y: 0, z: 0 });
14127
- break;
14128
- case shared.TempEntity.PARASITE_ATTACK:
14129
- case shared.TempEntity.MEDIC_CABLE_ATTACK:
14130
- this.writer.writeShort(ent || 0);
14131
- this.writer.writePos(pos);
14132
- this.writer.writePos(pos2 || { x: 0, y: 0, z: 0 });
14133
- break;
14134
- case shared.TempEntity.GRAPPLE_CABLE:
14135
- this.writer.writeShort(ent || 0);
14136
- this.writer.writePos(pos);
14137
- this.writer.writePos(pos2 || { x: 0, y: 0, z: 0 });
14138
- this.writer.writePos(dir || { x: 0, y: 0, z: 0 });
14139
- break;
14140
- case shared.TempEntity.LIGHTNING:
14141
- this.writer.writeShort(srcEnt || 0);
14142
- this.writer.writeShort(destEnt || 0);
14143
- this.writer.writePos(pos);
14144
- this.writer.writePos(pos2 || { x: 0, y: 0, z: 0 });
14145
- break;
14146
- case shared.TempEntity.FLASHLIGHT:
14147
- this.writer.writePos(pos);
14148
- this.writer.writeShort(ent || 0);
14149
- break;
14150
- case shared.TempEntity.FORCEWALL:
14151
- this.writer.writePos(pos);
14152
- this.writer.writePos(pos2 || { x: 0, y: 0, z: 0 });
14153
- this.writer.writeByte(color || 0);
14154
- break;
14155
- case shared.TempEntity.STEAM:
14156
- this.writer.writeShort(-1);
14157
- this.writer.writeByte(cnt || 0);
14158
- this.writer.writePos(pos);
14159
- this.writer.writeDir(dir || { x: 0, y: 0, z: 0 });
14160
- this.writer.writeByte(color || 0);
14161
- this.writer.writeShort(0);
14162
- break;
14163
- case shared.TempEntity.WIDOWBEAMOUT:
14164
- this.writer.writeShort(0);
14165
- // ent
14166
- // Fallthrough
14167
- case shared.TempEntity.HEATBEAM:
14168
- case shared.TempEntity.MONSTER_HEATBEAM:
14169
- this.writer.writeShort(ent || 0);
14170
- this.writer.writePos(pos);
14171
- this.writer.writePos(pos2 || { x: 0, y: 0, z: 0 });
14172
- this.writer.writeDir(dir || { x: 0, y: 0, z: 0 });
14173
- break;
14174
- default:
14175
- console.warn(`writeTempEntity: Unhandled type ${type}`);
14176
- break;
14274
+ constructor(writer, protocol = 34) {
14275
+ this.writer = writer || new shared.BinaryWriter(new Uint8Array(64 * 1024));
14276
+ this.protocol = protocol;
14277
+ }
14278
+ getData() {
14279
+ return this.writer.getData();
14280
+ }
14281
+ getOpcode(cmd) {
14282
+ if (this.protocol === 34) {
14283
+ switch (cmd) {
14284
+ case shared.ServerCommand.serverdata:
14285
+ return 13;
14286
+ case shared.ServerCommand.frame:
14287
+ return 5;
14288
+ case shared.ServerCommand.playerinfo:
14289
+ return 17;
14290
+ case shared.ServerCommand.packetentities:
14291
+ return 18;
14292
+ case shared.ServerCommand.deltapacketentities:
14293
+ return 19;
14294
+ case shared.ServerCommand.print:
14295
+ return 11;
14296
+ case shared.ServerCommand.centerprint:
14297
+ return 16;
14298
+ case shared.ServerCommand.stufftext:
14299
+ return 12;
14300
+ case shared.ServerCommand.sound:
14301
+ return 10;
14302
+ case shared.ServerCommand.temp_entity:
14303
+ return 9;
14304
+ case shared.ServerCommand.configstring:
14305
+ return 14;
14306
+ case shared.ServerCommand.spawnbaseline:
14307
+ return 15;
14308
+ case shared.ServerCommand.layout:
14309
+ return 7;
14310
+ case shared.ServerCommand.inventory:
14311
+ return 6;
14312
+ case shared.ServerCommand.muzzleflash:
14313
+ return 8;
14314
+ case shared.ServerCommand.muzzleflash2:
14315
+ return 20;
14316
+ }
14317
+ }
14318
+ return cmd;
14319
+ }
14320
+ writeCommand(cmd, protocol) {
14321
+ const proto = protocol ?? this.protocol;
14322
+ if (proto === 34 || proto === 0) {
14323
+ this.writer.writeByte(this.getOpcode(cmd));
14324
+ } else {
14325
+ this.writer.writeByte(cmd);
14326
+ }
14327
+ }
14328
+ writeServerData(protocol, serverCount, attractLoop, gameDir, playerNum, levelName) {
14329
+ this.writeCommand(shared.ServerCommand.serverdata);
14330
+ this.writer.writeLong(protocol);
14331
+ this.writer.writeLong(serverCount);
14332
+ this.writer.writeByte(attractLoop);
14333
+ this.writer.writeString(gameDir);
14334
+ this.writer.writeShort(playerNum);
14335
+ this.writer.writeString(levelName);
14336
+ }
14337
+ writeConfigString(index, str) {
14338
+ this.writeCommand(shared.ServerCommand.configstring);
14339
+ this.writer.writeShort(index);
14340
+ this.writer.writeString(str);
14341
+ }
14342
+ writeStuffText(text) {
14343
+ this.writeCommand(shared.ServerCommand.stufftext);
14344
+ this.writer.writeString(text);
14345
+ }
14346
+ writeCenterPrint(msg) {
14347
+ this.writeCommand(shared.ServerCommand.centerprint);
14348
+ this.writer.writeString(msg);
14349
+ }
14350
+ writePrint(level, msg) {
14351
+ this.writeCommand(shared.ServerCommand.print);
14352
+ this.writer.writeByte(level);
14353
+ this.writer.writeString(msg);
14354
+ }
14355
+ writeLayout(layout) {
14356
+ this.writeCommand(shared.ServerCommand.layout);
14357
+ this.writer.writeString(layout);
14358
+ }
14359
+ writeInventory(inventory) {
14360
+ this.writeCommand(shared.ServerCommand.inventory);
14361
+ for (const count of inventory) {
14362
+ this.writer.writeShort(count);
14363
+ }
14364
+ for (let i = inventory.length; i < 256; i++) {
14365
+ this.writer.writeShort(0);
14177
14366
  }
14178
14367
  }
14179
- writeSound(mask, soundNum, volume, attenuation, offset, ent, pos, protocolVersion = 0) {
14180
- this.writeCommand(shared.ServerCommand.sound, protocolVersion);
14368
+ writeMuzzleFlash(ent, weapon) {
14369
+ this.writeCommand(shared.ServerCommand.muzzleflash);
14370
+ this.writer.writeShort(ent);
14371
+ this.writer.writeByte(weapon);
14372
+ }
14373
+ writeMuzzleFlash2(ent, weapon) {
14374
+ this.writeCommand(shared.ServerCommand.muzzleflash2);
14375
+ this.writer.writeShort(ent);
14376
+ this.writer.writeByte(weapon);
14377
+ }
14378
+ writeSound(mask, soundNum, volume, attenuation, offset, ent, pos, protocol) {
14379
+ this.writeCommand(shared.ServerCommand.sound);
14181
14380
  this.writer.writeByte(mask);
14182
14381
  this.writer.writeByte(soundNum);
14183
- if (mask & 1) this.writer.writeByte(volume || 0);
14184
- if (mask & 2) this.writer.writeByte(attenuation || 0);
14185
- if (mask & 16) this.writer.writeByte(offset || 0);
14186
- if (mask & 8) this.writer.writeShort(ent || 0);
14187
- if (mask & 4 && pos) {
14382
+ if (mask & 1) this.writer.writeByte(volume);
14383
+ if (mask & 2) this.writer.writeByte(attenuation);
14384
+ if (mask & 16) this.writer.writeByte(offset);
14385
+ if (mask & 8) this.writer.writeShort(ent);
14386
+ if (mask & 4) {
14188
14387
  this.writer.writeCoord(pos.x);
14189
14388
  this.writer.writeCoord(pos.y);
14190
14389
  this.writer.writeCoord(pos.z);
14191
14390
  }
14192
14391
  }
14193
- writeDisconnect(protocolVersion = 0) {
14194
- this.writeCommand(shared.ServerCommand.disconnect, protocolVersion);
14195
- }
14196
- writeReconnect(protocolVersion = 0) {
14197
- this.writeCommand(shared.ServerCommand.reconnect, protocolVersion);
14198
- }
14199
- writeFrame(frame, protocolVersion) {
14200
- this.writeCommand(shared.ServerCommand.frame, protocolVersion);
14201
- this.writer.writeLong(frame.serverFrame);
14202
- this.writer.writeLong(frame.deltaFrame);
14203
- if (protocolVersion !== 25 && protocolVersion !== 26) {
14204
- this.writer.writeByte(frame.surpressCount);
14205
- }
14206
- this.writer.writeByte(frame.areaBytes);
14207
- if (frame.areaBytes > 0) {
14208
- this.writer.writeBytes(frame.areaBits);
14392
+ writeTempEntity(type, pos, pos2, dir, cnt, color, ent, srcEnt, destEnt) {
14393
+ this.writeCommand(shared.ServerCommand.temp_entity);
14394
+ this.writer.writeByte(type);
14395
+ if (pos) {
14396
+ this.writer.writePos(pos);
14209
14397
  }
14210
- this.writeCommand(shared.ServerCommand.playerinfo, protocolVersion);
14211
- this.writePlayerState(frame.playerState);
14212
- this.writePacketEntities(frame.packetEntities.entities, frame.packetEntities.delta, protocolVersion);
14213
14398
  }
14214
14399
  writePlayerState(ps) {
14400
+ this.writeCommand(shared.ServerCommand.playerinfo);
14215
14401
  let flags = 0;
14216
14402
  if (ps.pm_type !== 0) flags |= 1;
14217
14403
  if (ps.origin.x !== 0 || ps.origin.y !== 0 || ps.origin.z !== 0) flags |= 2;
@@ -14223,55 +14409,56 @@ var MessageWriter = class {
14223
14409
  if (ps.viewoffset.x !== 0 || ps.viewoffset.y !== 0 || ps.viewoffset.z !== 0) flags |= 128;
14224
14410
  if (ps.viewangles.x !== 0 || ps.viewangles.y !== 0 || ps.viewangles.z !== 0) flags |= 256;
14225
14411
  if (ps.kick_angles.x !== 0 || ps.kick_angles.y !== 0 || ps.kick_angles.z !== 0) flags |= 512;
14226
- if (ps.blend[0] !== 0 || ps.blend[1] !== 0 || ps.blend[2] !== 0 || ps.blend[3] !== 0) flags |= 1024;
14227
14412
  if (ps.gun_index !== 0) flags |= 4096;
14228
14413
  if (ps.gun_frame !== 0 || ps.gun_offset.x !== 0 || ps.gun_offset.y !== 0 || ps.gun_offset.z !== 0 || ps.gun_angles.x !== 0 || ps.gun_angles.y !== 0 || ps.gun_angles.z !== 0) flags |= 8192;
14414
+ if (ps.blend[0] !== 0 || ps.blend[1] !== 0 || ps.blend[2] !== 0 || ps.blend[3] !== 0) flags |= 1024;
14229
14415
  if (ps.fov !== 0) flags |= 2048;
14230
14416
  if (ps.rdflags !== 0) flags |= 16384;
14417
+ if (ps.watertype !== 0) flags |= 32768;
14231
14418
  this.writer.writeShort(flags);
14232
14419
  if (flags & 1) this.writer.writeByte(ps.pm_type);
14233
14420
  if (flags & 2) {
14234
- this.writer.writeCoord(ps.origin.x);
14235
- this.writer.writeCoord(ps.origin.y);
14236
- this.writer.writeCoord(ps.origin.z);
14421
+ this.writer.writeShort(ps.origin.x / 0.125);
14422
+ this.writer.writeShort(ps.origin.y / 0.125);
14423
+ this.writer.writeShort(ps.origin.z / 0.125);
14237
14424
  }
14238
14425
  if (flags & 4) {
14239
- this.writer.writeCoord(ps.velocity.x);
14240
- this.writer.writeCoord(ps.velocity.y);
14241
- this.writer.writeCoord(ps.velocity.z);
14426
+ this.writer.writeShort(ps.velocity.x / 0.125);
14427
+ this.writer.writeShort(ps.velocity.y / 0.125);
14428
+ this.writer.writeShort(ps.velocity.z / 0.125);
14242
14429
  }
14243
14430
  if (flags & 8) this.writer.writeByte(ps.pm_time);
14244
14431
  if (flags & 16) this.writer.writeByte(ps.pm_flags);
14245
14432
  if (flags & 32) this.writer.writeShort(ps.gravity);
14246
14433
  if (flags & 64) {
14247
- this.writer.writeShort(Math.round(ps.delta_angles.x * (32768 / 180)));
14248
- this.writer.writeShort(Math.round(ps.delta_angles.y * (32768 / 180)));
14249
- this.writer.writeShort(Math.round(ps.delta_angles.z * (32768 / 180)));
14434
+ this.writer.writeShort(ps.delta_angles.x / (180 / 32768));
14435
+ this.writer.writeShort(ps.delta_angles.y / (180 / 32768));
14436
+ this.writer.writeShort(ps.delta_angles.z / (180 / 32768));
14250
14437
  }
14251
14438
  if (flags & 128) {
14252
- this.writer.writeChar(Math.round(ps.viewoffset.x * 4));
14253
- this.writer.writeChar(Math.round(ps.viewoffset.y * 4));
14254
- this.writer.writeChar(Math.round(ps.viewoffset.z * 4));
14439
+ this.writer.writeByte(ps.viewoffset.x / 0.25);
14440
+ this.writer.writeByte(ps.viewoffset.y / 0.25);
14441
+ this.writer.writeByte(ps.viewoffset.z / 0.25);
14255
14442
  }
14256
14443
  if (flags & 256) {
14257
- this.writer.writeAngle16(ps.viewangles.x);
14258
- this.writer.writeAngle16(ps.viewangles.y);
14259
- this.writer.writeAngle16(ps.viewangles.z);
14444
+ this.writer.writeShort(ps.viewangles.x / (360 / 65536));
14445
+ this.writer.writeShort(ps.viewangles.y / (360 / 65536));
14446
+ this.writer.writeShort(ps.viewangles.z / (360 / 65536));
14260
14447
  }
14261
14448
  if (flags & 512) {
14262
- this.writer.writeChar(Math.round(ps.kick_angles.x * 4));
14263
- this.writer.writeChar(Math.round(ps.kick_angles.y * 4));
14264
- this.writer.writeChar(Math.round(ps.kick_angles.z * 4));
14449
+ this.writer.writeByte(ps.kick_angles.x / 0.25);
14450
+ this.writer.writeByte(ps.kick_angles.y / 0.25);
14451
+ this.writer.writeByte(ps.kick_angles.z / 0.25);
14265
14452
  }
14266
14453
  if (flags & 4096) this.writer.writeByte(ps.gun_index);
14267
14454
  if (flags & 8192) {
14268
14455
  this.writer.writeByte(ps.gun_frame);
14269
- this.writer.writeChar(Math.round(ps.gun_offset.x * 4));
14270
- this.writer.writeChar(Math.round(ps.gun_offset.y * 4));
14271
- this.writer.writeChar(Math.round(ps.gun_offset.z * 4));
14272
- this.writer.writeChar(Math.round(ps.gun_angles.x * 4));
14273
- this.writer.writeChar(Math.round(ps.gun_angles.y * 4));
14274
- this.writer.writeChar(Math.round(ps.gun_angles.z * 4));
14456
+ this.writer.writeByte(ps.gun_offset.x / 0.25);
14457
+ this.writer.writeByte(ps.gun_offset.y / 0.25);
14458
+ this.writer.writeByte(ps.gun_offset.z / 0.25);
14459
+ this.writer.writeByte(ps.gun_angles.x / 0.25);
14460
+ this.writer.writeByte(ps.gun_angles.y / 0.25);
14461
+ this.writer.writeByte(ps.gun_angles.z / 0.25);
14275
14462
  }
14276
14463
  if (flags & 1024) {
14277
14464
  this.writer.writeByte(ps.blend[0]);
@@ -14281,6 +14468,7 @@ var MessageWriter = class {
14281
14468
  }
14282
14469
  if (flags & 2048) this.writer.writeByte(ps.fov);
14283
14470
  if (flags & 16384) this.writer.writeByte(ps.rdflags);
14471
+ if (flags & 32768) this.writer.writeByte(ps.watertype);
14284
14472
  let statbits = 0;
14285
14473
  for (let i = 0; i < 32; i++) {
14286
14474
  if (ps.stats[i] !== 0) statbits |= 1 << i;
@@ -14290,112 +14478,121 @@ var MessageWriter = class {
14290
14478
  if (statbits & 1 << i) this.writer.writeShort(ps.stats[i]);
14291
14479
  }
14292
14480
  }
14293
- writePacketEntities(entities, delta, protocolVersion) {
14294
- this.writeCommand(delta ? shared.ServerCommand.deltapacketentities : shared.ServerCommand.packetentities, protocolVersion);
14481
+ writePacketEntities(entities, delta, protocol) {
14482
+ this.writeCommand(delta ? shared.ServerCommand.deltapacketentities : shared.ServerCommand.packetentities);
14295
14483
  for (const ent of entities) {
14296
- const force = !delta;
14297
- this.writeEntityState(ent, null, force, protocolVersion);
14484
+ this.writeDeltaEntity(createEmptyEntityState(), ent, true);
14298
14485
  }
14299
14486
  this.writer.writeShort(0);
14300
14487
  }
14301
- writeEntityState(to, from, force, protocolVersion) {
14488
+ writeFrame(frame, protocol) {
14489
+ this.writeCommand(shared.ServerCommand.frame);
14490
+ this.writer.writeLong(frame.serverFrame);
14491
+ this.writer.writeLong(frame.deltaFrame);
14492
+ if (protocol !== 26 && protocol !== 25) {
14493
+ this.writer.writeByte(frame.surpressCount);
14494
+ }
14495
+ this.writer.writeByte(frame.areaBytes);
14496
+ this.writer.writeBytes(frame.areaBits);
14497
+ this.writePlayerState(frame.playerState);
14498
+ this.writePacketEntities(frame.packetEntities.entities, frame.packetEntities.delta, protocol);
14499
+ }
14500
+ writeDeltaEntity(from, to, force) {
14302
14501
  let bits = 0;
14303
14502
  let bitsHigh = 0;
14304
- if (to.bits !== 0 && !force) {
14305
- bits = to.bits;
14306
- bitsHigh = to.bitsHigh;
14307
- } else {
14308
- if (to.modelindex !== 0) bits |= U_MODEL;
14309
- if (to.modelindex2 !== 0) bits |= U_MODEL2;
14310
- if (to.modelindex3 !== 0) bits |= U_MODEL3;
14311
- if (to.modelindex4 !== 0) bits |= U_MODEL4;
14312
- if (to.frame !== 0) {
14313
- if (to.frame >= 256) bits |= U_FRAME16;
14314
- else bits |= U_FRAME8;
14315
- }
14316
- if (to.skinnum !== 0) {
14317
- if (to.skinnum >= 256) bits |= U_SKIN16;
14318
- else bits |= U_SKIN8;
14319
- }
14320
- if (to.effects !== 0) {
14321
- if (to.effects >= 256) bits |= U_EFFECTS16;
14322
- else bits |= U_EFFECTS8;
14323
- }
14324
- if (to.renderfx !== 0) {
14325
- if (to.renderfx >= 256) bits |= U_RENDERFX16;
14326
- else bits |= U_RENDERFX8;
14327
- }
14328
- if (to.origin.x !== 0) bits |= U_ORIGIN1;
14329
- if (to.origin.y !== 0) bits |= U_ORIGIN2;
14330
- if (to.origin.z !== 0) bits |= U_ORIGIN3;
14331
- if (to.angles.x !== 0) bits |= U_ANGLE1;
14332
- if (to.angles.y !== 0) bits |= U_ANGLE2;
14333
- if (to.angles.z !== 0) bits |= U_ANGLE3;
14334
- if (to.old_origin.x !== 0 || to.old_origin.y !== 0 || to.old_origin.z !== 0) bits |= U_OLDORIGIN;
14335
- if (to.sound !== 0) bits |= U_SOUND;
14336
- if (to.event !== 0) bits |= U_EVENT;
14337
- if (to.solid !== 0) bits |= U_SOLID;
14338
- if (protocolVersion >= 2023) {
14339
- if (to.alpha !== 0) bits |= U_ALPHA;
14340
- if (to.scale !== 0) bits |= U_SCALE;
14341
- if (to.instanceBits !== 0) bits |= U_INSTANCE_BITS;
14342
- if (to.loopVolume !== 0) bits |= U_LOOP_VOLUME;
14343
- if (to.loopAttenuation !== 0) bitsHigh |= U_LOOP_ATTENUATION_HIGH;
14344
- if (to.owner !== 0) bitsHigh |= U_OWNER_HIGH;
14345
- if (to.oldFrame !== 0) bitsHigh |= U_OLD_FRAME_HIGH;
14346
- }
14347
- if (to.number >= 256) bits |= U_NUMBER16;
14348
- }
14349
- if (bitsHigh !== 0) bits |= U_MOREBITS4;
14350
- if ((bits & 4278190080) !== 0) bits |= U_MOREBITS3;
14351
- if ((bits & 16711680) !== 0) bits |= U_MOREBITS2;
14352
- if ((bits & 65280) !== 0) bits |= U_MOREBITS1;
14503
+ if (to.modelindex !== from.modelindex || force) bits |= shared.U_MODEL;
14504
+ if (to.modelindex2 !== from.modelindex2 || force) bits |= shared.U_MODEL2;
14505
+ if (to.modelindex3 !== from.modelindex3 || force) bits |= shared.U_MODEL3;
14506
+ if (to.modelindex4 !== from.modelindex4 || force) bits |= shared.U_MODEL4;
14507
+ if (to.frame !== from.frame || force) {
14508
+ if (to.frame >= 256) bits |= shared.U_FRAME16;
14509
+ else bits |= shared.U_FRAME8;
14510
+ }
14511
+ if (to.skinnum !== from.skinnum || force) {
14512
+ if (to.skinnum >= 256) bits |= shared.U_SKIN16;
14513
+ else bits |= shared.U_SKIN8;
14514
+ }
14515
+ if (to.effects !== from.effects || force) {
14516
+ if (to.effects >= 256) bits |= shared.U_EFFECTS16;
14517
+ else bits |= shared.U_EFFECTS8;
14518
+ }
14519
+ if (to.renderfx !== from.renderfx || force) {
14520
+ if (to.renderfx >= 256) bits |= shared.U_RENDERFX16;
14521
+ else bits |= shared.U_RENDERFX8;
14522
+ }
14523
+ if (to.origin.x !== from.origin.x || force) {
14524
+ if (to.origin.x !== 0) bits |= shared.U_ORIGIN1;
14525
+ }
14526
+ if (to.origin.y !== from.origin.y || force) {
14527
+ if (to.origin.y !== 0) bits |= shared.U_ORIGIN2;
14528
+ }
14529
+ if (to.origin.z !== from.origin.z || force) {
14530
+ if (to.origin.z !== 0) bits |= shared.U_ORIGIN3;
14531
+ }
14532
+ if (to.angles.x !== from.angles.x || force) {
14533
+ if (to.angles.x !== 0) bits |= shared.U_ANGLE1;
14534
+ }
14535
+ if (to.angles.y !== from.angles.y || force) {
14536
+ if (to.angles.y !== 0) bits |= shared.U_ANGLE2;
14537
+ }
14538
+ if (to.angles.z !== from.angles.z || force) {
14539
+ if (to.angles.z !== 0) bits |= shared.U_ANGLE3;
14540
+ }
14541
+ if (to.sound !== from.sound || force) bits |= shared.U_SOUND;
14542
+ if (to.event !== from.event || force) bits |= shared.U_EVENT;
14543
+ if (to.solid !== from.solid || force) bits |= shared.U_SOLID;
14544
+ if (this.protocol !== 34) {
14545
+ if (to.alpha !== from.alpha || force) bits |= shared.U_ALPHA;
14546
+ if (to.scale !== from.scale || force) bits |= shared.U_SCALE;
14547
+ if (to.instanceBits !== from.instanceBits || force) bits |= shared.U_INSTANCE_BITS;
14548
+ if (to.loopVolume !== from.loopVolume || force) bits |= shared.U_LOOP_VOLUME;
14549
+ if (to.loopAttenuation !== from.loopAttenuation || force) bitsHigh |= shared.U_LOOP_ATTENUATION_HIGH;
14550
+ if (to.owner !== from.owner || force) bitsHigh |= shared.U_OWNER_HIGH;
14551
+ if (to.oldFrame !== from.oldFrame || force) bitsHigh |= shared.U_OLD_FRAME_HIGH;
14552
+ }
14553
+ if (bitsHigh > 0) bits |= shared.U_MOREBITS4;
14554
+ if (bits & 4278190080) bits |= shared.U_MOREBITS3;
14555
+ if (bits & 4294901760) bits |= shared.U_MOREBITS2;
14556
+ if (bits & 4294967040) bits |= shared.U_MOREBITS1;
14353
14557
  this.writer.writeByte(bits & 255);
14354
- if (bits & U_MOREBITS1) this.writer.writeByte(bits >> 8 & 255);
14355
- if (bits & U_MOREBITS2) this.writer.writeByte(bits >> 16 & 255);
14356
- if (bits & U_MOREBITS3) this.writer.writeByte(bits >> 24 & 255);
14357
- if (protocolVersion >= 2023 && bits & U_MOREBITS4) {
14358
- this.writer.writeByte(bitsHigh & 255);
14359
- }
14360
- if (bits & U_NUMBER16) this.writer.writeShort(to.number);
14361
- else this.writer.writeByte(to.number);
14362
- if (bits & U_MODEL) this.writer.writeByte(to.modelindex);
14363
- if (bits & U_MODEL2) this.writer.writeByte(to.modelindex2);
14364
- if (bits & U_MODEL3) this.writer.writeByte(to.modelindex3);
14365
- if (bits & U_MODEL4) this.writer.writeByte(to.modelindex4);
14366
- if (bits & U_FRAME8) this.writer.writeByte(to.frame);
14367
- if (bits & U_FRAME16) this.writer.writeShort(to.frame);
14368
- if (bits & U_SKIN8 && bits & U_SKIN16) this.writer.writeLong(to.skinnum);
14369
- else if (bits & U_SKIN8) this.writer.writeByte(to.skinnum);
14370
- else if (bits & U_SKIN16) this.writer.writeShort(to.skinnum);
14371
- if (bits & U_EFFECTS8 && bits & U_EFFECTS16) this.writer.writeLong(to.effects);
14372
- else if (bits & U_EFFECTS8) this.writer.writeByte(to.effects);
14373
- else if (bits & U_EFFECTS16) this.writer.writeShort(to.effects);
14374
- if (bits & U_RENDERFX8 && bits & U_RENDERFX16) this.writer.writeLong(to.renderfx);
14375
- else if (bits & U_RENDERFX8) this.writer.writeByte(to.renderfx);
14376
- else if (bits & U_RENDERFX16) this.writer.writeShort(to.renderfx);
14377
- if (bits & U_ORIGIN1) this.writer.writeCoord(to.origin.x);
14378
- if (bits & U_ORIGIN2) this.writer.writeCoord(to.origin.y);
14379
- if (bits & U_ORIGIN3) this.writer.writeCoord(to.origin.z);
14380
- if (bits & U_ANGLE1) this.writer.writeAngle(to.angles.x);
14381
- if (bits & U_ANGLE2) this.writer.writeAngle(to.angles.y);
14382
- if (bits & U_ANGLE3) this.writer.writeAngle(to.angles.z);
14383
- if (bits & U_OLDORIGIN) {
14384
- this.writer.writeCoord(to.old_origin.x);
14385
- this.writer.writeCoord(to.old_origin.y);
14386
- this.writer.writeCoord(to.old_origin.z);
14387
- }
14388
- if (bits & U_SOUND) this.writer.writeByte(to.sound);
14389
- if (bits & U_EVENT) this.writer.writeByte(to.event);
14390
- if (bits & U_SOLID) this.writer.writeShort(to.solid);
14391
- if (protocolVersion >= 2023) {
14392
- if (bits & U_ALPHA) this.writer.writeByte(Math.round(to.alpha * 255));
14393
- if (bits & U_SCALE) this.writer.writeFloat(to.scale);
14394
- if (bits & U_INSTANCE_BITS) this.writer.writeLong(to.instanceBits);
14395
- if (bits & U_LOOP_VOLUME) this.writer.writeByte(Math.round(to.loopVolume * 255));
14396
- if (bitsHigh & U_LOOP_ATTENUATION_HIGH) this.writer.writeByte(Math.round(to.loopAttenuation * 255));
14397
- if (bitsHigh & U_OWNER_HIGH) this.writer.writeShort(to.owner);
14398
- if (bitsHigh & U_OLD_FRAME_HIGH) this.writer.writeShort(to.oldFrame);
14558
+ if (bits & shared.U_MOREBITS1) this.writer.writeByte(bits >> 8 & 255);
14559
+ if (bits & shared.U_MOREBITS2) this.writer.writeByte(bits >> 16 & 255);
14560
+ if (bits & shared.U_MOREBITS3) this.writer.writeByte(bits >> 24 & 255);
14561
+ if (bits & shared.U_MOREBITS4) this.writer.writeByte(bitsHigh & 255);
14562
+ if (to.number >= 256) {
14563
+ this.writer.writeShort(to.number);
14564
+ } else {
14565
+ this.writer.writeByte(to.number);
14566
+ }
14567
+ if (bits & shared.U_MODEL) this.writer.writeByte(to.modelindex);
14568
+ if (bits & shared.U_MODEL2) this.writer.writeByte(to.modelindex2);
14569
+ if (bits & shared.U_MODEL3) this.writer.writeByte(to.modelindex3);
14570
+ if (bits & shared.U_MODEL4) this.writer.writeByte(to.modelindex4);
14571
+ if (bits & shared.U_FRAME8) this.writer.writeByte(to.frame);
14572
+ if (bits & shared.U_FRAME16) this.writer.writeShort(to.frame);
14573
+ if (bits & shared.U_SKIN8) this.writer.writeByte(to.skinnum);
14574
+ if (bits & shared.U_SKIN16) this.writer.writeShort(to.skinnum);
14575
+ if (bits & shared.U_EFFECTS8) this.writer.writeByte(to.effects);
14576
+ if (bits & shared.U_EFFECTS16) this.writer.writeShort(to.effects);
14577
+ if (bits & shared.U_RENDERFX8) this.writer.writeByte(to.renderfx);
14578
+ if (bits & shared.U_RENDERFX16) this.writer.writeShort(to.renderfx);
14579
+ if (bits & shared.U_ORIGIN1) this.writer.writeCoord(to.origin.x);
14580
+ if (bits & shared.U_ORIGIN2) this.writer.writeCoord(to.origin.y);
14581
+ if (bits & shared.U_ORIGIN3) this.writer.writeCoord(to.origin.z);
14582
+ if (bits & shared.U_ANGLE1) this.writer.writeAngle(to.angles.x);
14583
+ if (bits & shared.U_ANGLE2) this.writer.writeAngle(to.angles.y);
14584
+ if (bits & shared.U_ANGLE3) this.writer.writeAngle(to.angles.z);
14585
+ if (bits & shared.U_SOUND) this.writer.writeByte(to.sound ?? 0);
14586
+ if (bits & shared.U_EVENT) this.writer.writeByte(to.event ?? 0);
14587
+ if (bits & shared.U_SOLID) this.writer.writeShort(to.solid);
14588
+ if (this.protocol !== 34) {
14589
+ if (bits & shared.U_ALPHA) this.writer.writeByte(to.alpha * 255);
14590
+ if (bits & shared.U_SCALE) this.writer.writeFloat(to.scale);
14591
+ if (bits & shared.U_INSTANCE_BITS) this.writer.writeLong(to.instanceBits);
14592
+ if (bits & shared.U_LOOP_VOLUME) this.writer.writeByte(to.loopVolume * 255);
14593
+ if (bitsHigh & shared.U_LOOP_ATTENUATION_HIGH) this.writer.writeByte(to.loopAttenuation * 255);
14594
+ if (bitsHigh & shared.U_OWNER_HIGH) this.writer.writeShort(to.owner);
14595
+ if (bitsHigh & shared.U_OLD_FRAME_HIGH) this.writer.writeShort(to.oldFrame);
14399
14596
  }
14400
14597
  }
14401
14598
  };
@@ -14430,294 +14627,210 @@ var DemoValidator = class {
14430
14627
  return { valid: true, version };
14431
14628
  }
14432
14629
  };
14433
- var DemoWriter = class {
14434
- constructor() {
14435
- this.writer = new shared.BinaryWriter();
14436
- }
14437
- writeBlock(data) {
14438
- this.writer.writeLong(data.byteLength);
14439
- this.writer.writeBytes(data);
14440
- }
14441
- writeEOF() {
14442
- this.writer.writeLong(-1);
14443
- }
14444
- getData() {
14445
- return this.writer.getData();
14446
- }
14447
- };
14448
-
14449
- // src/demo/delta.ts
14450
- function applyEntityDelta(to, from) {
14451
- const bits = from.bits;
14452
- const bitsHigh = from.bitsHigh;
14453
- to.number = from.number;
14454
- if (bits & U_MODEL) to.modelindex = from.modelindex;
14455
- if (bits & U_MODEL2) to.modelindex2 = from.modelindex2;
14456
- if (bits & U_MODEL3) to.modelindex3 = from.modelindex3;
14457
- if (bits & U_MODEL4) to.modelindex4 = from.modelindex4;
14458
- if (bits & U_FRAME8) to.frame = from.frame;
14459
- if (bits & U_FRAME16) to.frame = from.frame;
14460
- if (bits & U_SKIN8 || bits & U_SKIN16) to.skinnum = from.skinnum;
14461
- if (bits & U_EFFECTS8 || bits & U_EFFECTS16) to.effects = from.effects;
14462
- if (bits & U_RENDERFX8 || bits & U_RENDERFX16) to.renderfx = from.renderfx;
14463
- if (bits & U_ORIGIN1) to.origin.x = from.origin.x;
14464
- if (bits & U_ORIGIN2) to.origin.y = from.origin.y;
14465
- if (bits & U_ORIGIN3) to.origin.z = from.origin.z;
14466
- if (bits & U_ANGLE1) to.angles.x = from.angles.x;
14467
- if (bits & U_ANGLE2) to.angles.y = from.angles.y;
14468
- if (bits & U_ANGLE3) to.angles.z = from.angles.z;
14469
- if (bits & U_OLDORIGIN) {
14470
- to.old_origin.x = from.old_origin.x;
14471
- to.old_origin.y = from.old_origin.y;
14472
- to.old_origin.z = from.old_origin.z;
14473
- }
14474
- if (bits & U_SOUND) to.sound = from.sound;
14475
- if (bits & U_EVENT) to.event = from.event;
14476
- if (bits & U_SOLID) to.solid = from.solid;
14477
- if (bits & U_ALPHA) to.alpha = from.alpha;
14478
- if (bits & U_SCALE) to.scale = from.scale;
14479
- if (bits & U_INSTANCE_BITS) to.instanceBits = from.instanceBits;
14480
- if (bits & U_LOOP_VOLUME) to.loopVolume = from.loopVolume;
14481
- if (bitsHigh & U_LOOP_ATTENUATION_HIGH) to.loopAttenuation = from.loopAttenuation;
14482
- if (bitsHigh & U_OWNER_HIGH) to.owner = from.owner;
14483
- if (bitsHigh & U_OLD_FRAME_HIGH) to.oldFrame = from.oldFrame;
14484
- }
14485
14630
 
14486
14631
  // src/demo/clipper.ts
14487
14632
  var DemoClipper = class {
14488
- /**
14489
- * Extracts a raw clip from a demo between two offsets.
14490
- * Simply copies the message blocks.
14491
- */
14492
- extractClip(demo, start, end, controller) {
14493
- const reader = new DemoReader(demo.buffer);
14494
- const startFrame = start.type === "frame" ? start.frame : controller.timeToFrame(start.seconds);
14495
- const endFrame = end.type === "frame" ? end.frame : controller.timeToFrame(end.seconds);
14496
- if (!reader.seekToMessage(startFrame)) {
14497
- throw new Error(`Start frame ${startFrame} out of bounds`);
14498
- }
14499
- const startByteOffset = reader.getOffset();
14500
- let endByteOffset = demo.byteLength;
14501
- if (reader.seekToMessage(endFrame + 1)) {
14502
- endByteOffset = reader.getOffset();
14503
- }
14504
- const clipData = demo.slice(startByteOffset, endByteOffset);
14505
- const result = new Uint8Array(clipData.length + 4);
14506
- result.set(clipData);
14507
- const view = new DataView(result.buffer);
14508
- view.setInt32(clipData.length, -1, true);
14509
- return result;
14510
- }
14511
- extractDemoRange(demo, startFrame, endFrame) {
14512
- const controller = new DemoPlaybackController();
14513
- controller.loadDemo(demo.buffer);
14514
- return this.extractClip(demo, { type: "frame", frame: startFrame }, { type: "frame", frame: endFrame }, controller);
14633
+ constructor(buffer) {
14634
+ this.frames = [];
14635
+ this.configStrings = /* @__PURE__ */ new Map();
14636
+ this.baselines = /* @__PURE__ */ new Map();
14637
+ this.currentEntities = /* @__PURE__ */ new Map();
14638
+ if (buffer) {
14639
+ const sb = new StreamingBuffer(buffer.byteLength);
14640
+ sb.append(new Uint8Array(buffer));
14641
+ sb.setReadPosition(0);
14642
+ this.parser = new NetworkMessageParser(sb, this);
14643
+ } else {
14644
+ this.parser = new NetworkMessageParser(new StreamingBuffer(), this);
14645
+ }
14515
14646
  }
14516
- /**
14517
- * Captures the world state at a specific offset by playing the demo up to that point.
14518
- */
14519
- async captureWorldState(demo, atOffset) {
14520
- const controller = new DemoPlaybackController();
14521
- controller.loadDemo(demo.buffer);
14522
- const state = {
14523
- serverData: {
14524
- protocol: 0,
14525
- serverCount: 0,
14526
- attractLoop: 0,
14527
- gameDir: "",
14528
- playerNum: 0,
14529
- levelName: ""
14530
- },
14531
- configStrings: /* @__PURE__ */ new Map(),
14532
- entityBaselines: /* @__PURE__ */ new Map(),
14533
- playerState: createEmptyProtocolPlayerState(),
14534
- currentEntities: /* @__PURE__ */ new Map(),
14535
- currentFrameNumber: 0
14536
- };
14537
- const handler = {
14538
- onServerData: (protocol, serverCount, attractLoop, gameDir, playerNum, levelName, tickRate, demoType) => {
14539
- state.serverData = { protocol, serverCount, attractLoop, gameDir, playerNum, levelName, tickRate, demoType };
14540
- },
14541
- onConfigString: (index, str) => {
14542
- state.configStrings.set(index, str);
14543
- },
14544
- onSpawnBaseline: (entity) => {
14545
- state.entityBaselines.set(entity.number, { ...entity });
14546
- },
14547
- onFrame: (frame) => {
14548
- state.playerState = { ...frame.playerState };
14549
- state.currentFrameNumber = frame.serverFrame;
14550
- if (!frame.packetEntities.delta) {
14551
- state.currentEntities.clear();
14552
- }
14553
- const newEntities = /* @__PURE__ */ new Map();
14554
- if (frame.packetEntities.delta) {
14555
- for (const [key, val] of state.currentEntities) {
14556
- newEntities.set(key, val);
14557
- }
14558
- }
14559
- for (const deltaEnt of frame.packetEntities.entities) {
14560
- if (deltaEnt.bits & U_REMOVE) {
14561
- newEntities.delete(deltaEnt.number);
14562
- continue;
14563
- }
14564
- let prev = newEntities.get(deltaEnt.number);
14565
- if (!prev) {
14566
- const baseline = state.entityBaselines.get(deltaEnt.number);
14567
- if (baseline) {
14568
- prev = { ...baseline };
14569
- } else {
14570
- prev = createEmptyEntityState();
14571
- prev.number = deltaEnt.number;
14572
- }
14573
- } else {
14574
- prev = { ...prev };
14647
+ // Implementation of extractClip matching api.ts usage: extractClip(demoData, start, end, controller)
14648
+ extractClip(demoData, start, end, controller) {
14649
+ const reader = new DemoReader(demoData.buffer);
14650
+ const outputParts = [];
14651
+ let totalLength = 0;
14652
+ const startFrame = start.frame ?? -1;
14653
+ const endFrame = end.frame ?? Number.MAX_SAFE_INTEGER;
14654
+ let currentProtocol = 0;
14655
+ let blockIndex = 0;
14656
+ while (reader.nextBlock()) {
14657
+ const block = reader.getBlock();
14658
+ const blockData = block.data;
14659
+ let keepBlock = false;
14660
+ let frameNum = -1;
14661
+ let parsedSuccessfully = false;
14662
+ const probeHandler = {
14663
+ onServerData: (protocol) => {
14664
+ currentProtocol = protocol;
14665
+ keepBlock = true;
14666
+ parsedSuccessfully = true;
14667
+ },
14668
+ onConfigString: () => {
14669
+ keepBlock = true;
14670
+ parsedSuccessfully = true;
14671
+ },
14672
+ onSpawnBaseline: () => {
14673
+ keepBlock = true;
14674
+ parsedSuccessfully = true;
14675
+ },
14676
+ onFrame: (f) => {
14677
+ frameNum = f.serverFrame;
14678
+ parsedSuccessfully = true;
14679
+ if (frameNum >= startFrame && frameNum <= endFrame) {
14680
+ keepBlock = true;
14575
14681
  }
14576
- applyEntityDelta(prev, deltaEnt);
14577
- newEntities.set(deltaEnt.number, prev);
14682
+ },
14683
+ onCenterPrint: () => {
14684
+ parsedSuccessfully = true;
14685
+ },
14686
+ onStuffText: () => {
14687
+ parsedSuccessfully = true;
14688
+ },
14689
+ onPrint: () => {
14690
+ parsedSuccessfully = true;
14691
+ },
14692
+ onSound: () => {
14693
+ parsedSuccessfully = true;
14694
+ },
14695
+ onTempEntity: () => {
14696
+ parsedSuccessfully = true;
14697
+ },
14698
+ onLayout: () => {
14699
+ parsedSuccessfully = true;
14700
+ },
14701
+ onInventory: () => {
14702
+ parsedSuccessfully = true;
14703
+ },
14704
+ onMuzzleFlash: () => {
14705
+ parsedSuccessfully = true;
14706
+ },
14707
+ onMuzzleFlash2: () => {
14708
+ parsedSuccessfully = true;
14709
+ },
14710
+ onDisconnect: () => {
14711
+ parsedSuccessfully = true;
14712
+ },
14713
+ onReconnect: () => {
14714
+ parsedSuccessfully = true;
14715
+ },
14716
+ onDownload: () => {
14717
+ parsedSuccessfully = true;
14578
14718
  }
14579
- state.currentEntities = newEntities;
14580
- },
14581
- onCenterPrint: () => {
14582
- },
14583
- onStuffText: () => {
14584
- },
14585
- onPrint: () => {
14586
- },
14587
- onSound: () => {
14588
- },
14589
- onTempEntity: () => {
14590
- },
14591
- onLayout: () => {
14592
- },
14593
- onInventory: () => {
14594
- },
14595
- onMuzzleFlash: () => {
14596
- },
14597
- onMuzzleFlash2: () => {
14598
- },
14599
- onDisconnect: () => {
14600
- },
14601
- onReconnect: () => {
14602
- },
14603
- onDownload: () => {
14604
- }
14605
- };
14606
- controller.setHandler(handler);
14607
- const targetFrame = atOffset.type === "frame" ? atOffset.frame : controller.timeToFrame(atOffset.seconds);
14608
- controller.seek(targetFrame);
14609
- return state;
14610
- }
14611
- extractStandaloneClip(demo, start, end, worldState) {
14612
- const demoWriter = new DemoWriter();
14613
- const headerWriter = new MessageWriter();
14614
- const controller = new DemoPlaybackController();
14615
- controller.loadDemo(demo.buffer);
14616
- const startFrame = start.type === "frame" ? start.frame : controller.timeToFrame(start.seconds);
14617
- const endFrame = end.type === "frame" ? end.frame : controller.timeToFrame(end.seconds);
14618
- const { serverData } = worldState;
14619
- if (serverData.protocol >= 2023) {
14620
- headerWriter.writeServerDataRerelease(
14621
- serverData.protocol,
14622
- serverData.serverCount,
14623
- serverData.demoType || 0,
14624
- serverData.tickRate || 10,
14625
- serverData.gameDir,
14626
- serverData.playerNum,
14627
- serverData.levelName
14628
- );
14629
- } else {
14630
- headerWriter.writeServerData(
14631
- serverData.protocol,
14632
- serverData.serverCount,
14633
- serverData.attractLoop,
14634
- serverData.gameDir,
14635
- serverData.playerNum,
14636
- serverData.levelName
14637
- );
14638
- }
14639
- for (const [index, str] of worldState.configStrings) {
14640
- headerWriter.writeConfigString(index, str, serverData.protocol);
14641
- }
14642
- for (const entity of worldState.entityBaselines.values()) {
14643
- headerWriter.writeSpawnBaseline(entity, serverData.protocol);
14644
- }
14645
- const entities = Array.from(worldState.currentEntities.values());
14646
- const frame0 = {
14647
- serverFrame: 0,
14648
- // Rebase to 0
14649
- deltaFrame: -1,
14650
- surpressCount: 0,
14651
- areaBytes: 0,
14652
- areaBits: new Uint8Array(0),
14653
- // TODO: capture area bits?
14654
- playerState: worldState.playerState,
14655
- packetEntities: {
14656
- delta: false,
14657
- entities
14658
- // These are full entity states, writeFrame will handle them
14719
+ };
14720
+ const sb = new StreamingBuffer(blockData.getLength());
14721
+ sb.append(blockData.readData(blockData.getLength()));
14722
+ sb.setReadPosition(0);
14723
+ blockData.seek(0);
14724
+ const probeParser = new NetworkMessageParser(sb, probeHandler);
14725
+ if (currentProtocol > 0) probeParser.setProtocolVersion(currentProtocol);
14726
+ try {
14727
+ probeParser.parseMessage();
14728
+ } catch (e) {
14659
14729
  }
14660
- };
14661
- headerWriter.writeFrame(frame0, serverData.protocol);
14662
- demoWriter.writeBlock(headerWriter.getData());
14663
- const frameMap = /* @__PURE__ */ new Map();
14664
- frameMap.set(startFrame, 0);
14665
- const reader = new DemoReader(demo.buffer);
14666
- if (reader.seekToMessage(startFrame + 1)) {
14667
- let messageIndex = startFrame + 1;
14668
- while (messageIndex <= endFrame && reader.nextBlock()) {
14669
- const block = reader.getBlock();
14670
- const blockStream = block.data;
14671
- const blockWriter = new MessageWriter();
14672
- const passthroughHandler = {
14673
- onServerData: () => {
14674
- },
14675
- onConfigString: (idx, str) => blockWriter.writeConfigString(idx, str, serverData.protocol),
14676
- onSpawnBaseline: (ent) => blockWriter.writeSpawnBaseline(ent, serverData.protocol),
14677
- onCenterPrint: (msg) => blockWriter.writeCenterPrint(msg, serverData.protocol),
14678
- onStuffText: (txt) => blockWriter.writeStuffText(txt, serverData.protocol),
14679
- onPrint: (lvl, msg) => blockWriter.writePrint(lvl, msg, serverData.protocol),
14680
- onSound: (mask, s, v, a, o, e, p) => blockWriter.writeSound(mask, s, v, a, o, e, p, serverData.protocol),
14681
- onLayout: (l) => blockWriter.writeLayout(l, serverData.protocol),
14682
- onInventory: (inv) => blockWriter.writeInventory(inv, serverData.protocol),
14683
- onMuzzleFlash: (ent, w) => blockWriter.writeMuzzleFlash(ent, w, serverData.protocol),
14684
- onMuzzleFlash2: (ent, w) => blockWriter.writeMuzzleFlash2(ent, w, serverData.protocol),
14685
- onTempEntity: (t, p, p2, d, c, clr, e, s, de) => blockWriter.writeTempEntity(t, p, p2, d, c, clr, e, s, de, serverData.protocol),
14686
- onDisconnect: () => blockWriter.writeDisconnect(serverData.protocol),
14687
- onReconnect: () => blockWriter.writeReconnect(serverData.protocol),
14688
- onDownload: () => {
14689
- },
14690
- // Stub for download
14691
- onFrame: (frame) => {
14692
- const oldSeq = frame.serverFrame;
14693
- const oldDelta = frame.deltaFrame;
14694
- const newSeq = messageIndex - startFrame;
14695
- let newDelta = -1;
14696
- if (frameMap.has(oldDelta)) {
14697
- newDelta = frameMap.get(oldDelta);
14698
- } else {
14699
- frame.packetEntities.delta = false;
14700
- }
14701
- frameMap.set(oldSeq, newSeq);
14702
- frame.serverFrame = newSeq;
14703
- frame.deltaFrame = newDelta;
14704
- blockWriter.writeFrame(frame, serverData.protocol);
14705
- }
14706
- };
14707
- const blockParser = new NetworkMessageParser(blockStream, passthroughHandler, false);
14708
- blockParser.setProtocolVersion(serverData.protocol);
14709
- blockParser.parseMessage();
14710
- const blockData = blockWriter.getData();
14711
- if (blockData.byteLength > 0) {
14712
- demoWriter.writeBlock(blockData);
14730
+ if (!parsedSuccessfully) {
14731
+ if (blockIndex >= startFrame && blockIndex <= endFrame) {
14732
+ keepBlock = true;
14713
14733
  }
14714
- messageIndex++;
14715
14734
  }
14735
+ if (keepBlock) {
14736
+ const blockHeader = new Uint8Array(4);
14737
+ const view = new DataView(blockHeader.buffer);
14738
+ view.setUint32(0, blockData.getLength(), true);
14739
+ outputParts.push(blockHeader);
14740
+ const data = blockData.readData(blockData.getLength());
14741
+ outputParts.push(data);
14742
+ totalLength += 4 + data.length;
14743
+ }
14744
+ blockIndex++;
14745
+ }
14746
+ const eof = new Uint8Array(4);
14747
+ new DataView(eof.buffer).setInt32(0, -1, true);
14748
+ outputParts.push(eof);
14749
+ totalLength += 4;
14750
+ const result = new Uint8Array(totalLength);
14751
+ let offset = 0;
14752
+ for (const part of outputParts) {
14753
+ result.set(part, offset);
14754
+ offset += part.length;
14716
14755
  }
14717
- demoWriter.writeEOF();
14718
- return demoWriter.getData();
14756
+ return result;
14757
+ }
14758
+ extractDemoRange(demoData, startFrame, endFrame) {
14759
+ return this.extractClip(demoData, { frame: startFrame }, { frame: endFrame });
14760
+ }
14761
+ // Implement interface methods
14762
+ onServerData(protocol, serverCount, attractLoop, gameDir, playerNum, levelName) {
14763
+ this.serverData = { protocol, serverCount, attractLoop, gameDir, playerNum, levelName };
14764
+ }
14765
+ onConfigString(index, str) {
14766
+ this.configStrings.set(index, str);
14767
+ }
14768
+ onSpawnBaseline(entity) {
14769
+ this.baselines.set(entity.number, entity);
14770
+ }
14771
+ onFrame(frame) {
14772
+ this.frames.push(frame);
14773
+ }
14774
+ onCenterPrint(msg) {
14775
+ }
14776
+ onStuffText(msg) {
14777
+ }
14778
+ onPrint(level, msg) {
14779
+ }
14780
+ onSound(flags, soundNum, volume, attenuation, offset, ent, pos) {
14781
+ }
14782
+ onTempEntity(type, pos, pos2, dir, cnt, color, ent, srcEnt, destEnt) {
14783
+ }
14784
+ onLayout(layout) {
14785
+ }
14786
+ onInventory(inventory) {
14787
+ }
14788
+ onMuzzleFlash(ent, weapon) {
14789
+ }
14790
+ onMuzzleFlash2(ent, weapon) {
14791
+ }
14792
+ onDisconnect() {
14793
+ }
14794
+ onReconnect() {
14795
+ }
14796
+ onDownload(size, percent, data) {
14719
14797
  }
14720
14798
  };
14799
+ function applyEntityDelta(target, delta) {
14800
+ const bits = delta.bits;
14801
+ target.bits = bits;
14802
+ target.number = delta.number;
14803
+ if (bits & shared.U_MODEL) target.modelindex = delta.modelindex;
14804
+ if (bits & shared.U_MODEL2) target.modelindex2 = delta.modelindex2;
14805
+ if (bits & shared.U_MODEL3) target.modelindex3 = delta.modelindex3;
14806
+ if (bits & shared.U_MODEL4) target.modelindex4 = delta.modelindex4;
14807
+ if (bits & shared.U_FRAME8) target.frame = delta.frame;
14808
+ if (bits & shared.U_FRAME16) target.frame = delta.frame;
14809
+ if (bits & shared.U_SKIN8) target.skinnum = delta.skinnum;
14810
+ if (bits & shared.U_SKIN16) target.skinnum = delta.skinnum;
14811
+ if (bits & shared.U_EFFECTS8) target.effects = delta.effects;
14812
+ if (bits & shared.U_EFFECTS16) target.effects = delta.effects;
14813
+ if (bits & shared.U_RENDERFX8) target.renderfx = delta.renderfx;
14814
+ if (bits & shared.U_RENDERFX16) target.renderfx = delta.renderfx;
14815
+ if (bits & shared.U_ORIGIN1) target.origin.x = delta.origin.x;
14816
+ if (bits & shared.U_ORIGIN2) target.origin.y = delta.origin.y;
14817
+ if (bits & shared.U_ORIGIN3) target.origin.z = delta.origin.z;
14818
+ if (bits & shared.U_ANGLE1) target.angles.x = delta.angles.x;
14819
+ if (bits & shared.U_ANGLE2) target.angles.y = delta.angles.y;
14820
+ if (bits & shared.U_ANGLE3) target.angles.z = delta.angles.z;
14821
+ if (bits & shared.U_OLDORIGIN) {
14822
+ target.old_origin.x = delta.old_origin.x;
14823
+ target.old_origin.y = delta.old_origin.y;
14824
+ target.old_origin.z = delta.old_origin.z;
14825
+ }
14826
+ if (bits & shared.U_SOUND) target.sound = delta.sound;
14827
+ if (bits & shared.U_EVENT) target.event = delta.event;
14828
+ if (bits & shared.U_SOLID) target.solid = delta.solid;
14829
+ if (bits & shared.U_ALPHA) target.alpha = delta.alpha;
14830
+ if (bits & shared.U_SCALE) target.scale = delta.scale;
14831
+ if (bits & shared.U_INSTANCE_BITS) target.instanceBits = delta.instanceBits;
14832
+ if (bits & shared.U_LOOP_VOLUME) target.loopVolume = delta.loopVolume;
14833
+ }
14721
14834
 
14722
14835
  // src/assets/fileType.ts
14723
14836
  var FileType = /* @__PURE__ */ ((FileType2) => {
@@ -15634,6 +15747,126 @@ Object.defineProperty(exports, "SoundChannel", {
15634
15747
  enumerable: true,
15635
15748
  get: function () { return shared.SoundChannel; }
15636
15749
  });
15750
+ Object.defineProperty(exports, "U_ALPHA", {
15751
+ enumerable: true,
15752
+ get: function () { return shared.U_ALPHA; }
15753
+ });
15754
+ Object.defineProperty(exports, "U_ANGLE1", {
15755
+ enumerable: true,
15756
+ get: function () { return shared.U_ANGLE1; }
15757
+ });
15758
+ Object.defineProperty(exports, "U_ANGLE2", {
15759
+ enumerable: true,
15760
+ get: function () { return shared.U_ANGLE2; }
15761
+ });
15762
+ Object.defineProperty(exports, "U_ANGLE3", {
15763
+ enumerable: true,
15764
+ get: function () { return shared.U_ANGLE3; }
15765
+ });
15766
+ Object.defineProperty(exports, "U_EFFECTS16", {
15767
+ enumerable: true,
15768
+ get: function () { return shared.U_EFFECTS16; }
15769
+ });
15770
+ Object.defineProperty(exports, "U_EFFECTS8", {
15771
+ enumerable: true,
15772
+ get: function () { return shared.U_EFFECTS8; }
15773
+ });
15774
+ Object.defineProperty(exports, "U_EVENT", {
15775
+ enumerable: true,
15776
+ get: function () { return shared.U_EVENT; }
15777
+ });
15778
+ Object.defineProperty(exports, "U_FRAME16", {
15779
+ enumerable: true,
15780
+ get: function () { return shared.U_FRAME16; }
15781
+ });
15782
+ Object.defineProperty(exports, "U_FRAME8", {
15783
+ enumerable: true,
15784
+ get: function () { return shared.U_FRAME8; }
15785
+ });
15786
+ Object.defineProperty(exports, "U_INSTANCE_BITS", {
15787
+ enumerable: true,
15788
+ get: function () { return shared.U_INSTANCE_BITS; }
15789
+ });
15790
+ Object.defineProperty(exports, "U_LOOP_ATTENUATION_HIGH", {
15791
+ enumerable: true,
15792
+ get: function () { return shared.U_LOOP_ATTENUATION_HIGH; }
15793
+ });
15794
+ Object.defineProperty(exports, "U_LOOP_VOLUME", {
15795
+ enumerable: true,
15796
+ get: function () { return shared.U_LOOP_VOLUME; }
15797
+ });
15798
+ Object.defineProperty(exports, "U_MODEL", {
15799
+ enumerable: true,
15800
+ get: function () { return shared.U_MODEL; }
15801
+ });
15802
+ Object.defineProperty(exports, "U_MODEL2", {
15803
+ enumerable: true,
15804
+ get: function () { return shared.U_MODEL2; }
15805
+ });
15806
+ Object.defineProperty(exports, "U_MODEL3", {
15807
+ enumerable: true,
15808
+ get: function () { return shared.U_MODEL3; }
15809
+ });
15810
+ Object.defineProperty(exports, "U_MODEL4", {
15811
+ enumerable: true,
15812
+ get: function () { return shared.U_MODEL4; }
15813
+ });
15814
+ Object.defineProperty(exports, "U_OLDORIGIN", {
15815
+ enumerable: true,
15816
+ get: function () { return shared.U_OLDORIGIN; }
15817
+ });
15818
+ Object.defineProperty(exports, "U_OLD_FRAME_HIGH", {
15819
+ enumerable: true,
15820
+ get: function () { return shared.U_OLD_FRAME_HIGH; }
15821
+ });
15822
+ Object.defineProperty(exports, "U_ORIGIN1", {
15823
+ enumerable: true,
15824
+ get: function () { return shared.U_ORIGIN1; }
15825
+ });
15826
+ Object.defineProperty(exports, "U_ORIGIN2", {
15827
+ enumerable: true,
15828
+ get: function () { return shared.U_ORIGIN2; }
15829
+ });
15830
+ Object.defineProperty(exports, "U_ORIGIN3", {
15831
+ enumerable: true,
15832
+ get: function () { return shared.U_ORIGIN3; }
15833
+ });
15834
+ Object.defineProperty(exports, "U_OWNER_HIGH", {
15835
+ enumerable: true,
15836
+ get: function () { return shared.U_OWNER_HIGH; }
15837
+ });
15838
+ Object.defineProperty(exports, "U_REMOVE", {
15839
+ enumerable: true,
15840
+ get: function () { return shared.U_REMOVE; }
15841
+ });
15842
+ Object.defineProperty(exports, "U_RENDERFX16", {
15843
+ enumerable: true,
15844
+ get: function () { return shared.U_RENDERFX16; }
15845
+ });
15846
+ Object.defineProperty(exports, "U_RENDERFX8", {
15847
+ enumerable: true,
15848
+ get: function () { return shared.U_RENDERFX8; }
15849
+ });
15850
+ Object.defineProperty(exports, "U_SCALE", {
15851
+ enumerable: true,
15852
+ get: function () { return shared.U_SCALE; }
15853
+ });
15854
+ Object.defineProperty(exports, "U_SKIN16", {
15855
+ enumerable: true,
15856
+ get: function () { return shared.U_SKIN16; }
15857
+ });
15858
+ Object.defineProperty(exports, "U_SKIN8", {
15859
+ enumerable: true,
15860
+ get: function () { return shared.U_SKIN8; }
15861
+ });
15862
+ Object.defineProperty(exports, "U_SOLID", {
15863
+ enumerable: true,
15864
+ get: function () { return shared.U_SOLID; }
15865
+ });
15866
+ Object.defineProperty(exports, "U_SOUND", {
15867
+ enumerable: true,
15868
+ get: function () { return shared.U_SOUND; }
15869
+ });
15637
15870
  Object.defineProperty(exports, "attenuationToDistanceMultiplier", {
15638
15871
  enumerable: true,
15639
15872
  get: function () { return shared.attenuationToDistanceMultiplier; }
@@ -15729,36 +15962,6 @@ exports.Texture2D = Texture2D;
15729
15962
  exports.TextureCache = TextureCache;
15730
15963
  exports.TextureCubeMap = TextureCubeMap;
15731
15964
  exports.TgaParseError = TgaParseError;
15732
- exports.U_ALPHA = U_ALPHA;
15733
- exports.U_ANGLE1 = U_ANGLE1;
15734
- exports.U_ANGLE2 = U_ANGLE2;
15735
- exports.U_ANGLE3 = U_ANGLE3;
15736
- exports.U_EFFECTS16 = U_EFFECTS16;
15737
- exports.U_EFFECTS8 = U_EFFECTS8;
15738
- exports.U_EVENT = U_EVENT;
15739
- exports.U_FRAME16 = U_FRAME16;
15740
- exports.U_FRAME8 = U_FRAME8;
15741
- exports.U_INSTANCE_BITS = U_INSTANCE_BITS;
15742
- exports.U_LOOP_ATTENUATION_HIGH = U_LOOP_ATTENUATION_HIGH;
15743
- exports.U_LOOP_VOLUME = U_LOOP_VOLUME;
15744
- exports.U_MODEL = U_MODEL;
15745
- exports.U_MODEL2 = U_MODEL2;
15746
- exports.U_MODEL3 = U_MODEL3;
15747
- exports.U_MODEL4 = U_MODEL4;
15748
- exports.U_OLDORIGIN = U_OLDORIGIN;
15749
- exports.U_OLD_FRAME_HIGH = U_OLD_FRAME_HIGH;
15750
- exports.U_ORIGIN1 = U_ORIGIN1;
15751
- exports.U_ORIGIN2 = U_ORIGIN2;
15752
- exports.U_ORIGIN3 = U_ORIGIN3;
15753
- exports.U_OWNER_HIGH = U_OWNER_HIGH;
15754
- exports.U_REMOVE = U_REMOVE;
15755
- exports.U_RENDERFX16 = U_RENDERFX16;
15756
- exports.U_RENDERFX8 = U_RENDERFX8;
15757
- exports.U_SCALE = U_SCALE;
15758
- exports.U_SKIN16 = U_SKIN16;
15759
- exports.U_SKIN8 = U_SKIN8;
15760
- exports.U_SOLID = U_SOLID;
15761
- exports.U_SOUND = U_SOUND;
15762
15965
  exports.VertexArray = VertexArray;
15763
15966
  exports.VertexBuffer = VertexBuffer;
15764
15967
  exports.VirtualFileSystem = VirtualFileSystem;